UnemployedNinja
UnemployedNinja
CC#
Created by UnemployedNinja on 3/19/2024 in #help
✅ Is this necessary?
ty
7 replies
CC#
Created by UnemployedNinja on 3/19/2024 in #help
✅ Is this necessary?
Seems so simple put like that... nvm then lol
7 replies
CC#
Created by UnemployedNinja on 3/19/2024 in #help
✅ Is this necessary?
I've seen this around a few times when I was looking into how to use the HttpClient and am only know thinking about it, after learning a little more
7 replies
CC#
Created by UnemployedNinja on 3/15/2024 in #help
Thread.sleep in a constructor
It's for a library I'm creating, so I'd like to minimize the steps required
14 replies
CC#
Created by UnemployedNinja on 3/15/2024 in #help
Thread.sleep in a constructor
It's used to create a websocket client. The server I'm connecting to has a service API, which is used to get the websocket server for different regions. And the websocket client requires a URL to be created I could just contact the service API before, and then create the client, but I'd like to do it all in one
14 replies
CC#
Created by UnemployedNinja on 3/15/2024 in #help
Thread.sleep in a constructor
Yea, I did it like this lol
14 replies
CC#
Created by UnemployedNinja on 3/15/2024 in #help
Thread.sleep in a constructor
hmm I might go this route, ty
14 replies
CC#
Created by UnemployedNinja on 3/15/2024 in #help
Thread.sleep in a constructor
That's what I thought :/
14 replies
CC#
Created by UnemployedNinja on 3/14/2024 in #help
Specify timeout for websocket connection
I’ll look at SignalR though
5 replies
CC#
Created by UnemployedNinja on 3/14/2024 in #help
Specify timeout for websocket connection
Yea, I noticed there are quite a few. Websocket.Client had the most downloads (2m+) so I just went with that one
5 replies
CC#
Created by UnemployedNinja on 3/14/2024 in #help
Specify timeout for websocket connection
bump
5 replies
CC#
Created by UnemployedNinja on 3/13/2024 in #help
Struggling with generic class... design?
In short, my aim is to somehow only have one declaration of the T JsonDeserialize method, without affecting how BaseClass is used/accessed and without having to rewrite the same method and annotations 50 times
4 replies
CC#
Created by UnemployedNinja on 3/13/2024 in #help
Struggling with generic class... design?
My first thought was to make BaseClass a generic type, so I can have the following static method:
c#
public class BaseClass<T> where T : BaseClass<T> {
public BaseClass() { /* Constructor */ }

public static T? JsonDeserialize(string json) {
return JsonDeserialiseAs<T>(json);
}
}
c#
public class BaseClass<T> where T : BaseClass<T> {
public BaseClass() { /* Constructor */ }

public static T? JsonDeserialize(string json) {
return JsonDeserialiseAs<T>(json);
}
}
But this brings in two problems that I'd prefer to avoid: 1. I can't make a generic instance of BaseClass anymore and will always have to specify the type. 2. I always have to specify the type when checking if something is an instance of BaseClass. My next attempt was to make a typed version of BaseClass which the generic version will extend from, end then other classes from that:
c#
public class BaseClass { /* Holds all of the important constructors/properties etc */ }

public class BaseClass<T> : BaseClass where T : BaseClass<T> { // Only holds the type-dependant deserialization method.
public static T? JsonDeserialize(string json) {
return JsonDeserialiseAs<T>(json);
}
}

public class MyClassA : BaseClass<MyClassA> { }
c#
public class BaseClass { /* Holds all of the important constructors/properties etc */ }

public class BaseClass<T> : BaseClass where T : BaseClass<T> { // Only holds the type-dependant deserialization method.
public static T? JsonDeserialize(string json) {
return JsonDeserialiseAs<T>(json);
}
}

public class MyClassA : BaseClass<MyClassA> { }
Now I can access MyClassA.JsonDeserialize(json), however, MyClassA doesn't have access to all of the constructors from BaseClass. Meaning I'd have to duplicate, and rewrite them into BaseClass<T>, along with any annotations - dumb idea. I have a feeling the only way I can get what I want is by writing the JsonDeserialize method into every class that extends BaseClass
4 replies
CC#
Created by UnemployedNinja on 3/10/2024 in #help
Why does this require a cast?
Ty
23 replies
CC#
Created by UnemployedNinja on 3/10/2024 in #help
Why does this require a cast?
Ok, that makes sense
23 replies
CC#
Created by UnemployedNinja on 3/10/2024 in #help
Why does this require a cast?
Makes sense
23 replies
CC#
Created by UnemployedNinja on 3/10/2024 in #help
Why does this require a cast?
I see
23 replies
CC#
Created by UnemployedNinja on 3/10/2024 in #help
Why does this require a cast?
In a sense?
23 replies
CC#
Created by UnemployedNinja on 3/10/2024 in #help
Why does this require a cast?
So using ? is kind of like an entirely new type?
23 replies
CC#
Created by UnemployedNinja on 3/7/2024 in #help
Check value type of extended class instance
Just using is/is not
13 replies