WriteCodeYou often need to analyze existing types of information.
For example, analyze existing types to automatically generate classes, or automatically add some functions to existing classes.
Summarized a little experience
Take classa A; as an Example
1. You can use typeof (classa) or A. GetType () to obtain the type information. We recommend that you use typef () to avoid null references, and sometimes you do not need to construct a classa instance,
The performance of typeof (classa) is not poor at all. Do not confuse it with reflection,
2. For type. isprimitive, many common types are not native types.
For example, string datetime decimal is not of the native type.
According to msdn instructions native types only include: http://msdn.microsoft.com/en-us/magazine/bb984984.aspx
3. For arrays, typeof (classa [])
You can use type. isarray to determine whether an array is used.
You can use type. getelementtype to obtain the element type, which is equivalent to typeof (classa)
Arrays actually inherit from system. array, but arrays also implement the ienumerable <t> interface (this allows common types such as array and list <t> to be processed in the same way)
3. For generics, typeof (list <classa>)
You can use type. isgenerictype to determine whether it is a generic type.
You can use type. getgenerictypedefinition () to obtain the generic type (Open Type), which is equivalent to typeof (list <>)
Use type. getgenericarguments () to obtain the generic parameter set. The first element in the set is equivalent to typeof (classa)
For dictionary definitions such as Dictionary <string, classa>, type. getgenericarugment () returns two types: typeof (string) and typeof (classa). Its open type is typeof (Dictionary <,>)
4. You can call type. getinterfaces () to determine whether a type inherits from an interface.
For example, both array and list <t> inherit from ienumerable <t>, so that they can be processed in a unified manner.
5. Can the null value type be Int? Its open type is typeof (system. nullable <>)
The Open Type here refers to an incomplete type. You need to add parameters (generally generic parameters) to form a real type, such as list <>, added the wildcard parameter string to list <string>
Open type is not a complete type. You cannot create an instance directly.
The closed type is already a complete type. You can use new ..