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


C# MyClass.GetType方法代码示例

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


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

示例1: Test

 public static void Test()
 {
     MyClass hello = new MyClass();
     var type = hello.GetType();
     if (type.IsDefined(typeof(MyAttribute), false))
     {
         foreach (var item in MyAttribute.GetCustomAttributes(type))
         {
             var obj = item as MyAttribute;
             Console.WriteLine("Str:{0};B:{1};Color:{2}", obj.Str, obj.B, obj.Color);
         }
     }
     var a = hello.GetType().IsDefined(typeof(MyAttribute), false);//true
     var adsfsadf = MyAttribute.GetCustomAttributes(typeof(MyClass));//true
 }
开发者ID:henrydem,项目名称:yongfa365doc,代码行数:15,代码来源:MyAttribute.cs

示例2: Main

    public static void Main()
    {
        Type t = typeof(MyClass);

        //除了这种方法外,你也可以使用
        MyClass instance1 = new MyClass();
        Type t1 = instance1.GetType();

        MethodInfo[] x = t.GetMethods();
        foreach (MethodInfo xtemp in x)
        {
            Console.WriteLine(xtemp.ToString());
        }

        Console.WriteLine();

        MemberInfo[] x2 = t1.GetMembers();
        foreach (MemberInfo xtemp2 in x2)
        {
            Console.WriteLine(xtemp2.ToString());
        }

        Console.WriteLine();

        int radius = 3;
        Console.WriteLine("Area = {0} ", radius*radius*Math.PI);
        Console.WriteLine("The type is {0}", (radius*radius*Math.PI).GetType());

        Console.ReadLine();
    }
开发者ID:Nagato23,项目名称:CsBasic,代码行数:30,代码来源:typeofTest.cs

示例3: Main

		static void Main(string[] args)
		{
			MyClass mc = new MyClass(); // Create an instance of the class.
			Type t = mc.GetType(); // Get the Type object from the instance.

			// IsDefined
			bool isDefined = // Check the Type for the attribute.
			t.IsDefined(typeof(ReviewCommentAttribute), false);
			if( isDefined )
			{
				Console.WriteLine("ReviewComment is applied to type {0}", t.Name);
			}
			
			// GetCustomAttributes
			object[] AttArr = t.GetCustomAttributes( false );
			foreach ( Attribute a in AttArr )
			{
				ReviewCommentAttribute attr = a as ReviewCommentAttribute;
				if ( null != attr )
				{
					Console.WriteLine( "Description : {0}", attr.Description );
					Console.WriteLine( "Version Number : {0}", attr.VersionNumber );
					Console.WriteLine( "Reviewer ID : {0}", attr.ReviewerID );
				}
			}
		}
开发者ID:creating2000,项目名称:Codes,代码行数:26,代码来源:GetCustomAttributes.cs

示例4: PosTest4

 public void PosTest4()
 {
     MyClass tc1 = new MyClass();
     Type tpA = tc1.GetType();
     EventInfo eventinfo = tpA.GetEvent("Event", BindingFlags.Instance | BindingFlags.Public);
     MethodInfo methodinfo = eventinfo.GetRemoveMethod();
     Assert.Equal("Void remove_Event(Delegate1)", methodinfo.ToString());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:EventInfoGetRemoveMethod1.cs

示例5: Main

	static int Main ()
	{
		using (var v = new MyClass("foo"))
			if (v.GetType() != typeof (MyClass))
				return 1;
		
		return 0;
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:test-var-05.cs

示例6: Main

		static void Main(string[] args)
		{
			MyClass mc = new MyClass(); // Create an instance of the class.
			Type t = mc.GetType(); // Get the Type object from the instance.
			bool isDefined = // Check the Type for the attribute.
			t.IsDefined(typeof(ReviewCommentAttribute), false);
			if( isDefined )
			{
				Console.WriteLine("ReviewComment is applied to type {0}", t.Name);
			}
		}
开发者ID:creating2000,项目名称:Codes,代码行数:11,代码来源:IsDefined.cs

示例7: ApplyKeyGesturesTest

        public void ApplyKeyGesturesTest()
        {
            var instance = new MyClass();
            Type type = instance.GetType();
            UIElement inputBinder = instance.mainWindow;
            UIElement inputBinder2 = instance.subWindow;

            Assert.IsEmpty(inputBinder.InputBindings);
            Assert.IsEmpty(((RelayCommand)instance.FirstCommand).InputGestures);
            Assert.IsEmpty(inputBinder2.InputBindings);
            Assert.IsEmpty(((RelayCommand)instance.SecondCommand).InputGestures);

            // Apply gestures from "mainWindow"-targets to the mainWindow field.
            CommandKeyGestureAttribute.ApplyKeyGestures(type, inputBinder, instance);

            Assert.IsNotEmpty(inputBinder.InputBindings);
            Assert.AreEqual(1, inputBinder.InputBindings.Count);
            var inpBinding = inputBinder.InputBindings[0];
            Assert.AreSame(instance.FirstCommand, inpBinding.Command);
            var gesture = (KeyGesture)inpBinding.Gesture;
            Assert.AreEqual(Key.A, gesture.Key);
            Assert.AreEqual(ModifierKeys.Control, gesture.Modifiers);

            var rlay = (RelayCommand)instance.FirstCommand;
            Assert.IsNotEmpty(rlay.InputGestures);
            Assert.AreEqual(1, rlay.InputGestures.Count);
            var inpGesture = rlay.InputGestures[0];
            gesture = (KeyGesture)inpGesture;
            Assert.AreEqual(Key.A, gesture.Key);
            Assert.AreEqual(ModifierKeys.Control, gesture.Modifiers);

            Assert.IsEmpty(inputBinder2.InputBindings);
            Assert.IsEmpty(((RelayCommand)instance.SecondCommand).InputGestures);

            // Apply gestures from "subWindow"-targets to the subWindow field.
            CommandKeyGestureAttribute.ApplyKeyGestures(type, inputBinder2, instance);

            Assert.IsNotEmpty(inputBinder2.InputBindings);
            Assert.AreEqual(1, inputBinder2.InputBindings.Count);
            inpBinding = inputBinder2.InputBindings[0];
            Assert.AreSame(instance.SecondCommand, inpBinding.Command);
            gesture = (KeyGesture)inpBinding.Gesture;
            Assert.AreEqual(Key.B, gesture.Key);
            Assert.AreEqual(ModifierKeys.Alt, gesture.Modifiers);

            rlay = (RelayCommand)instance.SecondCommand;
            Assert.IsNotEmpty(rlay.InputGestures);
            Assert.AreEqual(1, rlay.InputGestures.Count);
            inpGesture = rlay.InputGestures[0];
            gesture = (KeyGesture)inpGesture;
            Assert.AreEqual(Key.B, gesture.Key);
            Assert.AreEqual(ModifierKeys.Alt, gesture.Modifiers);
        }
开发者ID:Jedzia,项目名称:BackBock,代码行数:53,代码来源:CommandKeyGestureAttributeTest.cs

示例8: TestMethod1

        public void TestMethod1()
        {
            var c = new MyClass();
            c.MyProperty = 13;

            Type info = c.GetType();
            Type info2 = typeof(MyClass);

            object result = info.GetProperty("MyProperty").GetValue(c);
            Console.WriteLine(result);

            object id = info.GetField("_id", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(c);
            info.GetField("_id", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(c, null);
            Console.WriteLine(id);
        }
开发者ID:riezebosch,项目名称:utvs,代码行数:15,代码来源:ReflectionDemo.cs


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