首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#2.0 Type.GetType()有关问题,请高手帮忙

2012-02-25 
c#2.0 Type.GetType()问题,急啊,请高手帮忙OrderornewOrder()TypetType.GetType(or)stringsNamet.Nam

c#2.0 Type.GetType()问题,急啊,请高手帮忙
Order   or   =   new   Order();
Type   t   =   Type.GetType(or);
string   sName   =   t.Name;
为什么sName取得的值为 "RunTimeType ",我跟踪t时发现:

+t{Name   =   "Order "   FullName   =   "Test.Order "}System.Type   {System.RuntimeType}
-entity.GetType(){Name   =   "RuntimeType "   FullName   =   "System.RuntimeType "}System.Type   {System.RuntimeType}
+[System.RuntimeType]{Name   =   "RuntimeType "   FullName   =   "System.RuntimeType "}System.RuntimeType
+base{Name   =   "RuntimeType "   FullName   =   "System.RuntimeType "}System.Reflection.MemberInfo   {System.RuntimeType}
+Assembly{mscorlib,   Version=2.0.0.0,   Culture=neutral,   PublicKeyToken=b77a5c561934e089}System.Reflection.Assembly
AssemblyQualifiedName "System.RuntimeType,   mscorlib,   Version=2.0.0.0,   Culture=neutral,   PublicKeyToken=b77a5c561934e089 "string
AttributesSerializable   |   BeforeFieldInitSystem.Reflection.TypeAttributes
+BaseType{Name   =   "Type "   FullName   =   "System.Type "}System.Type   {System.RuntimeType}
ContainsGenericParametersfalsebool
+DeclaringMethod“entity.GetType().DeclaringMethod”引发了“System.InvalidOperationException”类型的异常System.Reflection.MethodBase   {System.InvalidOperationException}
+DeclaringTypenullSystem.Type
FullName "System.RuntimeType "string
+GenericParameterAttributes“entity.GetType().GenericParameterAttributes”引发了“System.InvalidOperationException”类型的异常System.Reflection.GenericParameterAttributes   {System.InvalidOperationException}
+GenericParameterPosition“entity.GetType().GenericParameterPosition”引发了“System.InvalidOperationException”类型的异常int   {System.InvalidOperationException}
+GUID{97e69551-7329-39c5-ba61-2ca4b573e0e5}System.Guid
HasElementTypefalsebool
IsAbstractfalsebool
IsAnsiClasstruebool
IsArrayfalsebool
IsAutoClassfalsebool
IsAutoLayouttruebool
IsByReffalsebool
IsClasstruebool
IsCOMObjectfalsebool
IsContextfulfalsebool
IsEnumfalsebool
IsExplicitLayoutfalsebool
IsGenericParameterfalsebool
IsGenericTypefalsebool
IsGenericTypeDefinitionfalsebool
IsImportfalsebool
IsInterfacefalsebool
IsLayoutSequentialfalsebool
IsMarshalByReffalsebool
IsNestedfalsebool
IsNestedAssemblyfalsebool
IsNestedFamANDAssemfalsebool
IsNestedFamilyfalsebool
IsNestedFamORAssemfalsebool
IsNestedPrivatefalsebool
IsNestedPublicfalsebool
IsNotPublictruebool
IsPointerfalsebool
IsPrimitivefalsebool
IsPublicfalsebool
IsSealedfalsebool
IsSerializabletruebool
IsSpecialNamefalsebool
IsUnicodeClassfalsebool
IsValueTypefalsebool
IsVisiblefalsebool
MemberTypeTypeInfoSystem.Reflection.MemberTypes
+Module{CommonLanguageRuntimeLibrary}System.Reflection.Module
Namespace "System "string
+ReflectedTypenullSystem.Type
+StructLayoutAttribute{System.Runtime.InteropServices.StructLayoutAttribute}System.Runtime.InteropServices.StructLayoutAttribute
+TypeHandle{System.RuntimeTypeHandle}System.RuntimeTypeHandle
+TypeInitializer{Void   .cctor()}System.Reflection.ConstructorInfo   {System.Reflection.RuntimeConstructorInfo}
+UnderlyingSystemType{Name   =   "RuntimeType "   FullName   =   "System.RuntimeType "}System.Type   {System.RuntimeType}


+静态成员
+非公共成员


--------------------
这是怎么回事啊?我为什么取不到实际类型呢?请高手帮忙!!

[解决办法]
or.GetType()
[解决办法]
你使用typeof(Order)
[解决办法]
参见如下的代码:
string typeName = typeof(frmRules).Name;
Console.WriteLine(typeName );
[解决办法]
参见如下的代码:
string typeName = typeof(Order).Name;
Console.WriteLine(typeName );

热点排行