I have:
public class MyUserControl : WebUserControlBase <MyDocumentType>{...}
How do I get the TypeName of MyDocumentType
if I'm in another class?
You can access the type of a specific parameter by using square brackets, in the same way you would access an array element at index. Here is an example of how you would use the Parameters utility type for 2 functions that take the same object as a parameter. Copied!
The first step to dynamically invoking a generic method with reflection is to use reflection to get access to the MethodInfo of the generic method. To do that simply do this: var methodInfo = typeof(ClassWithGenericMethod). GetMethod("MethodName");
The most basic way to do reflection is to use the GetType() method, but we can also use reflection to get information about methods, constructors, properties, and more.
Reflection provides objects (of type Type) that describe assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties.
You can use something like this:
typeof(MyUserControl).BaseType.GetGenericArguments()[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With