本文整理汇总了C#中Example.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Example.GetType方法的具体用法?C# Example.GetType怎么用?C# Example.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Example
的用法示例。
在下文中一共展示了Example.GetType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFieldSetter_ValueTypeField_ReturnsFieldValue
public void GetFieldSetter_ValueTypeField_ReturnsFieldValue()
{
var input = new Example();
var expected = -1;
var fieldInfo = input.GetType().GetField("one");
Assert.NotNull(fieldInfo);
SetterDelegate setter = DynamicMethodGenerator.GetFieldSetter(fieldInfo);
Assert.NotNull(setter);
setter(input, expected);
Assert.Equal(expected, input.One);
}
示例2: GetFieldSetter_PrivateField_ReturnsFieldValue
public void GetFieldSetter_PrivateField_ReturnsFieldValue()
{
var input = new Example();
var expected = -2;
var fieldInfo = input.GetType().GetField("two", BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.FlattenHierarchy);
Assert.NotNull(fieldInfo);
SetterDelegate setter = DynamicMethodGenerator.GetFieldSetter(fieldInfo);
Assert.NotNull(setter);
setter(input, expected);
Assert.Equal(expected, fieldInfo.GetValue(input));
}
示例3: GetFieldGetter_ProtectedField_ReturnsFieldValue
public void GetFieldGetter_ProtectedField_ReturnsFieldValue()
{
var input = new Example();
var fieldInfo = input.GetType().GetField("c", BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.FlattenHierarchy);
Assert.NotNull(fieldInfo);
GetterDelegate getter = DynamicMethodGenerator.GetFieldGetter(fieldInfo);
Assert.NotNull(getter);
Assert.Equal("sea", getter(input));
}
示例4: GetFieldGetter_ValueTypeField_ReturnsFieldValue
public void GetFieldGetter_ValueTypeField_ReturnsFieldValue()
{
var input = new Example();
var fieldInfo = input.GetType().GetField("one");
Assert.NotNull(fieldInfo);
GetterDelegate getter = DynamicMethodGenerator.GetFieldGetter(fieldInfo);
Assert.NotNull(getter);
Assert.Equal(1, getter(input));
}
示例5: GetPropertySetter_PrivateSetterProperty_ReturnsPropertyValue
public void GetPropertySetter_PrivateSetterProperty_ReturnsPropertyValue()
{
var input = new Example();
var expected = "sun";
var propertyInfo = input.GetType().GetProperty("Re");
Assert.NotNull(propertyInfo);
SetterDelegate setter = DynamicMethodGenerator.GetPropertySetter(propertyInfo);
Assert.NotNull(setter);
setter(input, expected);
Assert.Equal(expected, input.Re);
}
示例6: GetPropertySetter_PrivateGetterProperty_ReturnsPropertyValue
public void GetPropertySetter_PrivateGetterProperty_ReturnsPropertyValue()
{
var input = new Example();
var expected = "myself";
var propertyInfo = input.GetType().GetProperty("Mi");
Assert.NotNull(propertyInfo);
SetterDelegate setter = DynamicMethodGenerator.GetPropertySetter(propertyInfo);
Assert.NotNull(setter);
setter(input, expected);
MethodInfo getter = propertyInfo.GetGetMethod(true);
Assert.NotNull(getter);
Assert.Equal(expected, getter.Invoke(input, null));
}
示例7: GetPropertySetter_SetterOnlyProperty_ReturnsPropertyValue
public void GetPropertySetter_SetterOnlyProperty_ReturnsPropertyValue()
{
var input = new Example();
var expected = -3;
var propertyInfo = input.GetType().GetProperty("Three_Setter");
Assert.NotNull(propertyInfo);
SetterDelegate setter = DynamicMethodGenerator.GetPropertySetter(propertyInfo);
Assert.NotNull(setter);
setter(input, expected);
Assert.Equal(expected, input.Three);
}
示例8: GetPropertySetter_AutoImplementedProperty_ReturnsPropertyValue
public void GetPropertySetter_AutoImplementedProperty_ReturnsPropertyValue()
{
var input = new Example();
var expected = "deer";
var propertyInfo = input.GetType().GetProperty("Do");
Assert.NotNull(propertyInfo);
SetterDelegate setter = DynamicMethodGenerator.GetPropertySetter(propertyInfo);
Assert.NotNull(setter);
setter(input, expected);
Assert.Equal(expected, input.Do);
}
示例9: GetPropertySetter_GetterOnlyProperty_ReturnsPropertyValue
public void GetPropertySetter_GetterOnlyProperty_ReturnsPropertyValue()
{
var input = new Example();
var propertyInfo = input.GetType().GetProperty("Three_Getter");
Assert.NotNull(propertyInfo);
SetterDelegate setter = DynamicMethodGenerator.GetPropertySetter(propertyInfo);
Assert.Null(setter);
}
示例10: GetPropertySetter_PrivateProperty_ReturnsPropertyValue
public void GetPropertySetter_PrivateProperty_ReturnsPropertyValue()
{
var input = new Example();
var expected = -2;
var propertyInfo = input.GetType().GetProperty("Two", BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.FlattenHierarchy);
Assert.NotNull(propertyInfo);
SetterDelegate setter = DynamicMethodGenerator.GetPropertySetter(propertyInfo);
Assert.NotNull(setter);
setter(input, expected);
MethodInfo getter = propertyInfo.GetGetMethod(true);
Assert.NotNull(getter);
Assert.Equal(expected, getter.Invoke(input, null));
}
示例11: GetPropertySetter_PublicReferenceTypeProperty_ReturnsPropertyValue
public void GetPropertySetter_PublicReferenceTypeProperty_ReturnsPropertyValue()
{
var input = new Example();
var expected = "alpha";
var propertyInfo = input.GetType().GetProperty("A");
Assert.NotNull(propertyInfo);
SetterDelegate setter = DynamicMethodGenerator.GetPropertySetter(propertyInfo);
Assert.NotNull(setter);
setter(input, expected);
Assert.Equal(expected, input.A);
}
示例12: GetPropertyGetter_PrivateGetterProperty_ReturnsPropertyValue
public void GetPropertyGetter_PrivateGetterProperty_ReturnsPropertyValue()
{
var input = new Example();
var propertyInfo = input.GetType().GetProperty("Mi");
Assert.NotNull(propertyInfo);
GetterDelegate getter = DynamicMethodGenerator.GetPropertyGetter(propertyInfo);
Assert.NotNull(getter);
Assert.Equal("me", getter(input));
}
示例13: GetPropertyGetter_PrivateProperty_ReturnsPropertyValue
public void GetPropertyGetter_PrivateProperty_ReturnsPropertyValue()
{
var input = new Example();
var propertyInfo = input.GetType().GetProperty("Two", BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.FlattenHierarchy);
Assert.NotNull(propertyInfo);
GetterDelegate getter = DynamicMethodGenerator.GetPropertyGetter(propertyInfo);
Assert.NotNull(getter);
Assert.Equal(2, getter(input));
}