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


C# BaseClass.GetType方法代码示例

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


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

示例1: SetValue_SetsPropertyValue

        public void SetValue_SetsPropertyValue()
        {
            // Arrange
            var expected = "new value";
            var instance = new BaseClass { PropA = "old value" };
            var helper = PropertyHelper.GetProperties(
                instance.GetType()).First(prop => prop.Name == "PropA");

            // Act
            helper.SetValue(instance, expected);

            // Assert
            Assert.Equal(expected, instance.PropA);
        }
开发者ID:leloulight,项目名称:Common,代码行数:14,代码来源:PropertyHelperTest.cs

示例2: PropertyHelper_ReturnsSetterDelegate

        public void PropertyHelper_ReturnsSetterDelegate()
        {
            // Arrange
            var expected = "new value";
            var instance = new BaseClass { PropA = "old value" };
            var helper = PropertyHelper.GetProperties(
                instance.GetType()).First(prop => prop.Name == "PropA");

            // Act and Assert
            Assert.NotNull(helper.ValueSetter);
            helper.ValueSetter(instance, expected);

            // Assert
            Assert.Equal(expected, instance.PropA);
        }
开发者ID:leloulight,项目名称:Common,代码行数:15,代码来源:PropertyHelperTest.cs

示例3: Main

        static void Main()
        {
            BaseClass b = new BaseClass();
            DerivedClass d = new DerivedClass();

            // Display custom attributes for each class.
            Console.WriteLine("Attributes on Base Class:");
            object[] attrs = b.GetType().GetCustomAttributes(true);
            foreach (Attribute attr in attrs)
            {
                Console.WriteLine(attr);
            }

            Console.WriteLine("Attributes on Derived Class:");
            attrs = d.GetType().GetCustomAttributes(true);
            foreach (Attribute attr in attrs)
            {
                Console.WriteLine(attr);
            }
            Console.ReadKey();
        }
开发者ID:chenshunji2012,项目名称:HiHub,代码行数:21,代码来源:Program.cs

示例4: MakeFastPropertySetter_SetsPropertyValues_ForPublicAndNobPublicProperties

        public void MakeFastPropertySetter_SetsPropertyValues_ForPublicAndNobPublicProperties()
        {
            // Arrange
            var instance = new BaseClass();
            var typeInfo = instance.GetType().GetTypeInfo();
            var publicProperty = typeInfo.GetDeclaredProperty("PropA");
            var protectedProperty = typeInfo.GetDeclaredProperty("PropProtected");
            var publicPropertySetter = PropertyHelper.MakeFastPropertySetter(publicProperty);
            var protectedPropertySetter = PropertyHelper.MakeFastPropertySetter(protectedProperty);

            // Act
            publicPropertySetter(instance, "TestPublic");
            protectedPropertySetter(instance, "TestProtected");

            // Assert
            Assert.Equal("TestPublic", instance.PropA);
            Assert.Equal("TestProtected", instance.GetPropProtected());
        }
开发者ID:sparraguerra,项目名称:Common,代码行数:18,代码来源:PropertyHelperTest.cs

示例5: BinderShouldBeUsedForProperties

		public void BinderShouldBeUsedForProperties ()
		{
			using (var serStream = new MemoryStream ()) {
				var binder = new CustomSerBinder ();

				// serialize
				var original = new BaseClass () {
					Other = new OtherClass ()
				};
				var formatter = new BinaryFormatter ();
				formatter.Binder = binder;
				formatter.Serialize (serStream, original);

				// deserialize, making sure we're using a new formatter, just to be thorough
				formatter = new BinaryFormatter ();
				formatter.Binder = binder;
				serStream.Seek (0, SeekOrigin.Begin);
				var deserialized = formatter.Deserialize (serStream);

				Assert.AreEqual (original.GetType (), deserialized.GetType ());
				Assert.AreEqual (original.Other.GetType (), ((BaseClass)deserialized).Other.GetType ());
			}
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:23,代码来源:BinaryFormatterTest.cs


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