C #PassedTypeAttackers can access any data type.
1. There are three methods to obtain a Type reference of a given Type:
A. Use the typeof operator, such as Typet = typeof (int );
B. Use the GetType () method, such as int I; Type t = I. GetType ();
C. UseTypeStatic Method GetType (), such as Type t = Type. GetType ("System. Double ");
2. Type attributes:
Name: Name of the data type;
FullName: a fully qualified name for the data type, including the namespace;
Namespace: a data-type Namespace;
BaseType: basic type;
UnderlyingSystemType: ing type;
3. Type method:
GetMethod (): returns information about a method;
GetMethods (): returns information about all methods.
TestType. cs:
TestTypeView.cs:
Using System;
Using System. Text;
Using System. Windows. Forms;
Using System. Reflection;
Namespace Magci. Test. Reflection
{
Public class TestTypeView
{
Public static StringBuilder OutputText = new StringBuilder ();
Public static void Main ()
{
Type t = typeof (double );
AnalyzeType (t );
MessageBox. Show (OutputText. ToString ());
}
Public static void AnalyzeType (Type t)
{
// Data type name
OutputText. Append ("\ nType Name:" + t. Name );
// A fully qualified name for the data type, including the namespace
OutputText. Append ("\ nFull Name:" + t. FullName );
// Data type namespace
OutputText. Append ("\ nNamespace:" + t. Namespace );
// Direct basic type
Type tBase = t. BaseType;
If (tBase! = Null)
{
OutputText. Append ("\ nBase Type:" + tBase. Name );
}
// Ing type
Type tUnderlyingSystem = t. UnderlyingSystemType;
If (tUnderlyingSystem! = Null)
{
OutputText. Append ("\ nUnderlyingSystem Type:" + tUnderlyingSystem. Name );
}
// All public methods
OutputText. Append ("\ n \ nPublic members :");
MemberInfo [] methods = t. GetMethods ();
Foreach (MemberInfo method in methods)
{
OutputText. Append ("\ n" + method. DeclaringType + "" + method. MemberType + "" + method. Name );
}
}
}
}