当前位置: 首页>>代码示例>>C#>>正文


C# TestClass.GetType方法代码示例

本文整理汇总了C#中System.TestClass.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# TestClass.GetType方法的具体用法?C# TestClass.GetType怎么用?C# TestClass.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TestClass的用法示例。


在下文中一共展示了TestClass.GetType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SystemReflectionType_ObjectGetType_Test0

        public MFTestResults SystemReflectionType_ObjectGetType_Test0()
        {
            bool fRes = true;

            ///
            /// Test object.GetType method for various types (including
            /// reflection types and arrays of reflection types).
            /// 
            object o = (object)1;
            fRes &= (o.GetType() == typeof(int));

            o = (object)typeof(Type);
            fRes &= o.GetType() == typeof(Type).GetType();

            o = AppDomain.CurrentDomain.GetAssemblies();
            fRes &= o.GetType() == typeof(Assembly[]);

            o = new TestClass();
            fRes &= o.GetType() == typeof(TestClass);

            o = new TestStruct();
            fRes &= o.GetType() == typeof(TestStruct);

            o = new MyDelegate(MyDelegateImpl);
            fRes &= o.GetType() == typeof(MyDelegate);

            o = (new MyDelegate(MyDelegateImpl)).Method;
            Debug.Print("object (MethodInfo) GetType: " + o.GetType().ToString());

            MethodInfo mi = typeof(SystemReflectionTypeTests).GetMethod("MyDelegateImpl", BindingFlags.Static | BindingFlags.NonPublic);
            fRes &= o.GetType() == mi.GetType();

            return fRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:34,代码来源:SystemReflectionTypeTests.cs

示例2: Test

        public void Test()
        {
            TestClass o = new TestClass();
            var p = o.GetType().GetProperty("A");
            p.SetValue(o, 10,null);

            int value = (int)p.Get(o);

            Assert.IsTrue(value == 10);
        }
开发者ID:netcasewqs,项目名称:nlite,代码行数:10,代码来源:FieldTest.cs

示例3: BindToClassProperty

        public void BindToClassProperty()
        {
            var tc = new TestClass();

            var classProp = new BoundMember<int>(tc, tc.GetType().GetProperty("Property"));

            tc.Property = 5;
            Assert.AreEqual(5, classProp.Value);
            classProp.Value = 10;
            Assert.AreEqual(10, tc.Property);
        }
开发者ID:sq,项目名称:Fracture,代码行数:11,代码来源:BindTests.cs

示例4: BindToClassField

        public void BindToClassField()
        {
            var tc = new TestClass();

            var classField = new BoundMember<int>(tc, tc.GetType().GetField("Field"));

            tc.Field = 5;
            Assert.AreEqual(5, classField.Value);
            classField.Value = 10;
            Assert.AreEqual(10, tc.Field);
        }
开发者ID:sq,项目名称:Fracture,代码行数:11,代码来源:BindTests.cs

示例5: GetCacherTest

        public void GetCacherTest()
        {
            var cf = new MemoryCacherFactory(new StubCachePolicyFactory(), new ObjectCacheFactory());
            var ph = new PropertyHelper(cf);
            var tci = new TestClassImpl
            {
                I = 1
            };
            var tc = new TestClass
            {
                I = 2
            };

            var r1 = ph.Get(tci.GetType().GetProperty("I"), tci);
            var r2 = ph.Get(tc.GetType().GetProperty("I"), tc);

            Assert.AreEqual(tci.I, r1);
            Assert.AreEqual(tc.I, r2);
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:19,代码来源:PropertyHelperTests.cs

示例6: SystemReflectionType_RuntimeType_Test1

        public MFTestResults SystemReflectionType_RuntimeType_Test1()
        {
            bool fRes = true;
            ArrayList list = new ArrayList();
            int i = 0;

            ///
            /// Test the RuntimeType class members
            /// 
            TestClass cls = new TestClass();

            // Test Type members for a class type
            Type t = cls.GetType();
            Assembly asm = t.Assembly;
            list.Add(asm);
            fRes &= ((Assembly)list[i]).GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= asm.GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= t.Name == "TestClass";
            fRes &= t.FullName == "Microsoft.SPOT.Platform.Tests.SystemReflectionTypeTests+TestClass";
            fRes &= t.BaseType == typeof(object);
            fRes &= t.GetElementType() == null;

            MethodInfo []mis = t.GetMethods();
            fRes &= mis[0].Name == "Method1";
            mis = t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
            fRes &= mis[0].Name == "Method2";
            fRes &= t.GetMethod("Method1") != null;
            fRes &= t.GetMethod("Method2", BindingFlags.Instance | BindingFlags.NonPublic) != null;
            
            FieldInfo[] fis = t.GetFields();
            fRes &= fis[0].Name == "m_Field1";
            fis = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            fRes &= fis[0].Name == "m_Field2";
            fRes &= t.GetField("m_Field1") != null;
            fRes &= t.GetField("m_Field2", BindingFlags.NonPublic | BindingFlags.Instance) != null;
            fRes &= t.GetConstructor(new Type[] { }) != null;
            
            Type[] ifaces = t.GetInterfaces();
            fRes &= ifaces.Length == 2;
            fRes &= ifaces[0].Name == "IInterface1";
            fRes &= ifaces[1].Name == "IInterface2";
            fRes &= t.IsSubclassOf(typeof(object));
            i++;

            // test Type members for a struct valuetype
            TestStruct str = new TestStruct();
            t = str.GetType();
            asm = t.Assembly;
            list.Add(asm);
            fRes &= ((Assembly)list[i]).GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= asm.GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= t.Name == "TestStruct";
            fRes &= t.FullName == "Microsoft.SPOT.Platform.Tests.SystemReflectionTypeTests+TestStruct";
            fRes &= t.BaseType == typeof(System.ValueType);
            fRes &= t.GetInterfaces().Length == 0;
            fRes &= t.GetElementType() == null;
            i++;

            // test Type members for an Assembly reflection type
            Assembly asmObj = typeof(TestClass).Assembly;
            t = asmObj.GetType();
            asm = t.Assembly;
            list.Add(asm);
            fRes &= ((Assembly)list[i]).GetName().Name == "mscorlib";
            fRes &= asm.GetName().Name == "mscorlib";
            fRes &= t.Name == "Assembly";
            fRes &= t.FullName == "System.Reflection.Assembly";
            fRes &= t.BaseType == typeof(Object);
            fRes &= t.GetInterfaces().Length == 0;
            fRes &= t.GetElementType() == null;

            mis = typeof(TestClass).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            t = mis.GetType();
            fRes &= t.Name == "RuntimeMethodInfo[]";
            fRes &= t.FullName == "System.Reflection.RuntimeMethodInfo[]";
            fRes &= t.BaseType == typeof(Array);
            fRes &= t.GetInterfaces().Length > 0;
            fRes &= t.GetElementType().Name == "RuntimeMethodInfo";

            // test Type members for a delegate
            Delegate del = new MyDelegate(MyDelegateImpl);
            t = del.GetType();
            fRes &= t.DeclaringType == null;
            fRes &= t.Name == "MyDelegate";
            fRes &= t.BaseType == typeof(MulticastDelegate);

            // test Type members for an enum
            TestEnum en = TestEnum.Item1;
            t = en.GetType();
            fRes &= t.DeclaringType == typeof(SystemReflectionTypeTests);
            fRes &= t.IsEnum;
            fRes &= !t.IsAbstract;
            fRes &= !t.IsClass;
            fRes &= !t.IsPublic;
            fRes &= t.IsValueType;

            return fRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:98,代码来源:SystemReflectionTypeTests.cs

示例7: SetCacherTest

        public void SetCacherTest()
        {
            var cf = new MemoryCacherFactory(new StubCachePolicyFactory(), new ObjectCacheFactory());
            var ph = new PropertyHelper(cf);
            var tci = new TestClassImpl();
            var tc = new TestClass();

            ph.Set(tci.GetType().GetProperty("I"), tci, 1);
            ph.Set(tc.GetType().GetProperty("I"), tc, 2);

            Assert.AreEqual(tci.I, 1);
            Assert.AreEqual(tc.I, 2);
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:13,代码来源:PropertyHelperTests.cs


注:本文中的System.TestClass.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。