
How can I pass in a func with a generic type parameter?
Mar 24, 2014 · 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. …
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<T> which I need to pass into a method that expects a Foo<Bar>. I can do the …
Create Generic method constraining T to an Enum
Sep 17, 2008 · Create Generic method constraining T to an Enum Asked 16 years, 10 months ago Modified 1 month ago Viewed 529k times
Generics in C#, using type of a variable as parameter
Feb 11, 2015 · 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. …
Calling a static method on a generic type parameter
Oct 13, 2008 · This answer cleverly "abuses" the somehow inconsistent rule, that you can, in your base class, create new objects of yet-unknown generic type, inheriting that base class - but …
Newest Questions - Stack Overflow
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Try Teams for free Explore Teams
How do I make the return type of a method generic?
Apr 5, 2024 · This may not be a best practice but it worked for me. This method takes in an array of generic type and a value to add to the end of the array. The array is then copied with the …
Mocking generic methods in Moq without specifying T
Oct 6, 2016 · I couldn't find any information on mocking the generic methods with a generic mock method, using Moq. The only thing I found so far was mocking the generic methods per …
Can I Create a Dictionary of Generic Types? - Stack Overflow
I'd like to create a Dictionary object, with string Keys, holding values which are of a generic type. I imagine that it would look something like this: Dictionary<string, List<T>> d = new
Cast to generic type in C# - Stack Overflow
Jun 28, 2016 · 1 As mentioned, you cannot cast it directly. One possible solution is to have those generic types inherit from a non-generic interface, in which case you can still invoke methods …