generic-type-argument

Reflection - Getting the generic parameters from a System.Type instance

If I have the following code: MyType<int> anInstance = new MyType<int>(); Type type = anInstance.GetType(); How can I find out which type parameter(s) "anInstance" was instantiated with, by looking at the type variable ? Is it possible ? ...

How to turn a Type instance into a generic type argument

I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent); } Foo(typeof(Person)); The Deserialize<ty> doesn't work because it expects Deserialize<Person> instead. How do I work around this? I'd also like to understand how generics work and why it won't accept ty which is type...

Extension methods for specific generic types

I'm attempting to create various extension method for a generic type bound to specific generic type parameters in F#, but the language does not seem to be allowing me: What I want to do is something like the following: type IEnumerable<int> with member this.foo = this.ToString() Yet it gives me the compiler error (underli...

Can I have generics in a Class Property?

I have a Class that is defined as Public MustInherit Class Entity(Of T As Entity(Of T)) And various classes derived from it. I would like to have another class accept all of the derived objects as a property, but I cannot seeem to find a workable syntax. If it were a parameter of a sub, I could say Public Sub Foo(T As Entity(Of T))...