Type , . - ( ) , .
, , 2.1.
, , :
string GetTypeDescription(Type type)
{ return type.IsClass? "class"
: type.IsInterface? "interface"
: type.IsArray? "array"
: type.IsEnum? "enum"
: type.IsValueType? "struct"
: "";
}
2.1 - ,
IsAbstract | |
IsClass | ? (.. value Type ) |
IsSealed | ? |
IsInterface | ? (, - !) |
IsCOMObject | COM- .NET? |
IsValueType | value type (-)? |
IsEnum | ? |
IsPrimitive | (.. bool, byte, sbyte, short, ushort, int, uint, long, ulong, char, double, float)? |
IsArray | . ElementType. |
IsPointer | ? ElementType. |
IsByRef | , ? , ElementType. |
HasElementType | HasElementType = IsArray || IsPointer || IsByRef. .. , " " ElementType. |
() . . , , . , . GetMembers.
public MemberInfo[] GetMembers();
public abstract MemberInfo[] GetMembers(BindingFlags);
, . , (public) , , . , BindingFlags.Public | BindingFlags.Instance, . , BindingFlags.Static. , , BindingFlags.NonPublic.
Type, .
|
|
2.2 Type
GetConstructors | . ConstructorInfo. |
GetCustomAttributes | . -. |
GetEvents | , . EventInfo. |
GetFields | . FieldInfo. |
GetInterfaces | , . Type. |
GetMembers | ( , , , ..) MemberInfo. |
GetMethods | . MethodInfo. |
GetNestedTypes | . Type. |
GetProperties | (properties) . PropertyInfo. |
GetTypeArray | ( ). Type. |
, , , , - , , , (ConstructorInfo, EventInfo, FieldInfo, MethodInfo, PropertyInfo) MemberInfo.
.
public static string TraceCtorsOf(Type type)
{ string trace = "";
ConstructorInfo[] arrCI = type.GetConstructors();
foreach (ConstructorInfo ci in arrCI)
{ trace += (ci.IsStatic? "static ": "")
+ (ci.IsPrivate? "private ": "")
+ (ci.IsFamily? "protected ": "")
+ (ci.IsAssembly? "internal ": "")
+ ci.Name;
ParameterInfo[] arrParamInfo = ci.GetParameters();
trace += "(";
for (int i = 0; i!= arrParamInfo.Length; i++)
{ ParameterInfo parInf = arrParamInfo[i];
trace += (i!= 0? ", ": "")
+ (parInf.IsIn? "in ": "")
+ (parInf.IsOut? "out ": "")
+ (parInf.IsOptional? "optional ": "")
+ (parInf.IsLcid? "lcid ": "")
+ parInf.ParameterType.Name + " "
+ parInf.Name
+ ((parInf.DefaultValue!= DBNull.Value)
? (" = " + parInf.DefaultValue): "")
;
}
trace += ");\r\n";
}
return trace;
}
, . , - (EventInfo, MethodInfo, ConstructorInfo), GetParameters (), ParameterInfo. : , , , (in/out) .