本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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());
}
示例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 ());
}
}