|
- void in C# generics? - Stack Overflow
I have a generic method that takes a request and provides a response public Tres DoSomething<Tres, Treq>(Tres response, Treq request) { *stuff* } But I don't always want a response for my request, and I don't always want to feed request data to get a response I also don't want to have to copy and paste methods in their entirety to make minor changes What I want, is to be able to do this
- Using Mockito to mock classes with generic parameters
Is there a clean method of mocking a class with generic parameters? Say I have to mock a class Foo lt;T gt; which I need to pass into a method that expects a Foo lt;Bar gt; I can do the following
- How to register dependency injection with generic types? (. net core)
How to register dependency injection with generic types? ( net core) Asked 6 years, 1 month ago Modified 3 years, 9 months ago Viewed 76k times
- Using List lt;T gt; in C# (Generics) - Stack Overflow
That's not how generics work MyMethod(List<T> list) is an invalid method signature (unless your class is a generic class with a Type Parameter T)
- Generics in C#, using type of a variable as parameter
Why? Because under the hood, the compiler will go away and create a new type (sometimes called a closed generic type) for each different usage of the "open" generic type In other words, after compilation, DoesEntityExist<int> is a different type to DoesEntityExist<string> This is how the compiler is able to enfore compile-time type safety
- How can I pass in a func with a generic type parameter?
You can certainly define generic delegates, after all, that's exactly what Func and Action are They are treated as generic definitions, just like generic interfaces and classes are However, you cannot use generic definitions in method signatures, only parameterized generic types Quite simply you cannot do what you are trying to achieve with a delegate alone
- Can I make a generic optional, defaulting to a certain class?
My question is related to Is there a reasonable approach to quot;default quot; type parameters in C# Generics?, but using an inner generic class that approach doesn't work Given code like this:
- Create Generic method constraining T to an Enum
Create Generic method constraining T to an Enum Asked 16 years, 10 months ago Modified 30 days ago Viewed 528k times
|
|
|