本文整理汇总了C#中System.Reflection.PropertyInfo.GetSetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetSetMethod方法的具体用法?C# PropertyInfo.GetSetMethod怎么用?C# PropertyInfo.GetSetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetSetMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitDeserialize
public void EmitDeserialize(PropertyInfo property, ref EmitHelper deserializeEmit)
{
var propertyType = property.PropertyType;
var propertyNullLabel = deserializeEmit.DefineLabel();
var propertyNotNullLabel = deserializeEmit.DefineLabel();
var propertyInstanceType = deserializeEmit.DeclareLocal(typeof(Type));
var indexLocal = deserializeEmit.DeclareLocal(typeof(int));
var objectExistsLocal = deserializeEmit.DefineLabel();
var objectNotExistsLocal = deserializeEmit.DefineLabel();
deserializeEmit
.ldarg_1
.call(typeof(BinaryReader).GetMethod("ReadInt32"))
.stloc(indexLocal)
.ldloc(indexLocal)
.ldc_i4_m1
.ceq
.brfalse(propertyNotNullLabel)
.ldarg_0
.ldnull
.call(property.GetSetMethod())
.br(propertyNullLabel)
.MarkLabel(propertyNotNullLabel)
.ldarg_2
.ldloc(indexLocal)
.call(typeof(IDictionary<int, object>).GetMethod("ContainsKey", new Type[] { typeof(int) }))
.brfalse(objectNotExistsLocal)
.ldarg_0
.ldarg_2
.ldloc(indexLocal)
.call(typeof(IDictionary<int, object>).GetMethod("get_Item", new Type[] { typeof(int) }))
.castclass(propertyType)
.call(property.GetSetMethod())
.br(objectExistsLocal)
.MarkLabel(objectNotExistsLocal)
.ldarg_1
.call(typeof(BinaryReader).GetMethod("ReadString"))
.call(typeof(Type).GetMethod("GetType", new Type[] { typeof(string) }))
.stloc(propertyInstanceType)
.ldarg_0
.ldloc(propertyInstanceType)
.call(typeof(Activator).GetMethod("CreateInstance", new Type[] { typeof(Type) }))
.call(typeof(Converter).GetMethod("Convert", new[] { typeof(object) }))
.castclass(propertyType)
.call(property.GetSetMethod())
.ldarg_2
.ldloc(indexLocal)
.ldarg_0
.call(property.GetGetMethod())
.call(typeof(IDictionary<int, object>).GetMethod("Add", new[] { typeof(int), typeof(object) }))
.ldarg_0
.call(property.GetGetMethod())
.castclass(typeof(ISerializable))
.ldarg_1
.ldarg_2
.call(typeof(ISerializable).GetMethod("Deserialize", new Type[] { typeof(BinaryReader), typeof(IDictionary<int, object>) }))
.MarkLabel(objectExistsLocal)
.MarkLabel(propertyNullLabel);
}
示例2: fsMetaProperty
internal fsMetaProperty(PropertyInfo property) {
_memberInfo = property;
StorageType = property.PropertyType;
JsonName = GetJsonName(property);
MemberName = property.Name;
IsPublic = (property.GetGetMethod() != null && property.GetGetMethod().IsPublic) && (property.GetSetMethod() != null && property.GetSetMethod().IsPublic);
CanRead = property.CanRead;
CanWrite = property.CanWrite;
}
示例3: InspectedProperty
/// <summary>
/// Initializes a new instance of the PropertyMetadata class from a property member.
/// </summary>
public InspectedProperty(PropertyInfo property)
{
MemberInfo = property;
StorageType = property.PropertyType;
CanWrite = property.GetSetMethod(/*nonPublic:*/ true) != null;
IsStatic = (property.GetGetMethod(/*nonPublic:*/ true) ?? property.GetSetMethod(/*nonPublic:*/ true)).IsStatic;
SetupNames();
}
示例4: fsMetaProperty
internal fsMetaProperty(PropertyInfo property) {
_memberInfo = property;
StorageType = property.PropertyType;
MemberName = property.Name;
IsPublic = (property.GetGetMethod() != null && property.GetGetMethod().IsPublic) &&
(property.GetSetMethod() != null && property.GetSetMethod().IsPublic);
CanRead = property.CanRead;
CanWrite = property.CanWrite;
CommonInitialize();
}
示例5: PropertyDescriptor
/// <summary>
/// Initializes a new instance of the <see cref="PropertyDescriptor"/> class.
/// </summary>
/// <param name="propertyInfo">The property information.</param>
public PropertyDescriptor(PropertyInfo propertyInfo)
: base(propertyInfo)
{
if (propertyInfo == null) throw new ArgumentNullException("propertyInfo");
this.propertyInfo = propertyInfo;
getMethod = propertyInfo.GetGetMethod(false);
if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(false) != null)
{
setMethod = propertyInfo.GetSetMethod(false);
}
}
示例6: PropertyDescriptor
/// <summary>
/// Initializes a new instance of the <see cref="PropertyDescriptor" /> class.
/// </summary>
/// <param name="propertyInfo">The property information.</param>
/// <param name="defaultNameComparer">The default name comparer.</param>
/// <exception cref="System.ArgumentNullException">propertyInfo</exception>
public PropertyDescriptor(PropertyInfo propertyInfo, StringComparer defaultNameComparer)
: base(propertyInfo, defaultNameComparer)
{
if (propertyInfo == null) throw new ArgumentNullException("propertyInfo");
this.propertyInfo = propertyInfo;
getMethod = propertyInfo.GetGetMethod(true);
if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(!IsPublic) != null)
{
setMethod = propertyInfo.GetSetMethod(!IsPublic);
}
}
示例7: FromPropertyInfo
private SchemaInfo FromPropertyInfo(PropertyInfo pi)
{
if (!this.IsMapped(pi))
return null;
Type propertyType = pi.PropertyType;
bool nullableTypeDetected = propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == CachedTypes.PureNullableType;
SchemaInfo schema = new SchemaInfo(pi.Name, nullableTypeDetected ? propertyType.GetGenericArguments()[0] : propertyType);
//NotMapped gibi bir standart
KeyAttribute keyAtt = pi.GetCustomAttribute<KeyAttribute>();
if (null != keyAtt)
schema.IsKey = true;
if (nullableTypeDetected)
schema.IsNullable = true;
else
{
if (propertyType.IsClass)
schema.IsNullable = true;
else if (propertyType.IsValueType)
schema.IsNullable = false;
}
bool hasSetMethod = pi.GetSetMethod() != null;
if (!hasSetMethod)
schema.ReadOnly = true;
this.SetExtendedSchema(schema, pi);
return schema;
}
示例8: PocoFeatureAttributeDefinition
public PocoFeatureAttributeDefinition(PropertyInfo propertyInfo, FeatureAttributeAttribute att)
{
AttributeName = propertyInfo.Name;
if (!string.IsNullOrEmpty(att.AttributeName)) AttributeName = att.AttributeName;
AttributeDescription = att.AttributeDescription;
AttributeType = propertyInfo.PropertyType;
if (propertyInfo.CanRead)
{
_getMethod = propertyInfo.GetGetMethod();
_static = _getMethod.IsStatic;
}
if (propertyInfo.CanWrite)
{
_setMethod = propertyInfo.GetSetMethod();
}
else
{
_readonly = true;
}
/*
var att = propertyInfo.GetCustomAttributes(typeof (FeatureAttributeAttribute), true);
if (att.Length > 0) CorrectByAttribute((FeatureAttributeAttribute)att[0]);
*/
CorrectByAttribute(att);
}
示例9: IsAReadWriteProperty
bool IsAReadWriteProperty(PropertyInfo propertyInfo)
{
if (!propertyInfo.GetSetMethod(true).IsPublic || !propertyInfo.GetGetMethod(true).IsPublic)
throw new InvalidOperationException("Tweakable property {" + propertyInfo.ReflectedType + "." + propertyInfo.Name + "} is of the wrong type (should be public read/write)");
return true;
}
示例10: PropertyObject
public PropertyObject(PropertyInfo md)
: base()
{
getter = md.GetGetMethod(true);
setter = md.GetSetMethod(true);
info = md;
}
示例11: CreatePropertySetter
public static Action<object, object> CreatePropertySetter(PropertyInfo property)
{
if (property == null)
throw new ArgumentNullException("property");
if (!property.CanWrite)
return null;
MethodInfo setMethod = property.GetSetMethod();
DynamicMethod dm = new DynamicMethod("PropertySetter", null, new Type[] { typeof(object), typeof(object) }, property.DeclaringType, true);
ILGenerator il = dm.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
Type type = property.PropertyType;
if (type.GetTypeInfo().IsValueType)
il.Emit(OpCodes.Unbox_Any, type);
else
il.Emit(OpCodes.Castclass, type);
if (!property.DeclaringType.GetTypeInfo().IsValueType)
il.EmitCall(OpCodes.Callvirt, setMethod, null);
else
il.EmitCall(OpCodes.Call, setMethod, null);
il.Emit(OpCodes.Ret);
return dm.CreateDelegate(typeof(Action<object, object>)) as Action<object, object>;
}
示例12: ObjectProperty
/// <summary> 表示一个可以获取或者设置其内容的对象属性
/// </summary>
/// <param name="property">属性信息</param>
public ObjectProperty(PropertyInfo property)
{
Field = false;
MemberInfo = property; //属性信息
OriginalType = property.PropertyType;
var get = property.GetGetMethod(true); //获取属性get方法,不论是否公开
var set = property.GetSetMethod(true); //获取属性set方法,不论是否公开
if (set != null) //set方法不为空
{
CanWrite = true; //属性可写
Static = set.IsStatic; //属性是否为静态属性
IsPublic = set.IsPublic;
}
if (get != null) //get方法不为空
{
CanRead = true; //属性可读
Static = get.IsStatic; //get.set只要有一个静态就是静态
IsPublic = IsPublic || get.IsPublic;
}
ID = System.Threading.Interlocked.Increment(ref Literacy.Sequence);
UID = Guid.NewGuid();
Init();
TypeCodes = TypeInfo.TypeCodes;
Attributes = new AttributeCollection(MemberInfo);
var mapping = Attributes.First<IMemberMappingAttribute>();
if (mapping != null)
{
MappingName = mapping.Name;
}
}
示例13: CreatePropertySetter
public static SetValueDelegate CreatePropertySetter(PropertyInfo property)
{
if (property == null) {
throw new ArgumentNullException("property");
}
if (!property.CanWrite) {
return null;
}
var setMethod = property.GetSetMethod();
var dm = new DynamicMethod("PropertySetter", null, new Type[] { typeof(object), typeof(object) }, property.DeclaringType, true);
ILGenerator il = dm.GetILGenerator();
if (!setMethod.IsStatic) {
il.Emit(OpCodes.Ldarg_0);
}
il.Emit(OpCodes.Ldarg_1);
EmitCastToReference(il, property.PropertyType);
if (!setMethod.IsStatic && !property.DeclaringType.IsValueType) {
il.EmitCall(OpCodes.Callvirt, setMethod, null);
} else {
il.EmitCall(OpCodes.Call, setMethod, null);
}
il.Emit(OpCodes.Ret);
return (SetValueDelegate)dm.CreateDelegate(typeof(SetValueDelegate));
}
示例14: GetSetMethod
static Action<object, object> GetSetMethod(PropertyInfo property, bool includeNonPublic)
{
ParameterExpression instance = Expression.Parameter(typeof(object), "instance");
ParameterExpression value = Expression.Parameter(typeof(object), "value");
// value as T is slightly faster than (T)value, so if it's not a value type, use that
UnaryExpression instanceCast;
#if !NETFX_CORE
if (property.DeclaringType.IsValueType)
#else
if (property.DeclaringType.GetTypeInfo().IsValueType)
#endif
instanceCast = Expression.Convert(instance, property.DeclaringType);
else
instanceCast = Expression.TypeAs(instance, property.DeclaringType);
UnaryExpression valueCast;
#if !NETFX_CORE
if (property.PropertyType.IsValueType)
#else
if (property.PropertyType.GetTypeInfo().IsValueType)
#endif
valueCast = Expression.Convert(value, property.PropertyType);
else
valueCast = Expression.TypeAs(value, property.PropertyType);
#if !NETFX_CORE
MethodCallExpression call = Expression.Call(instanceCast, property.GetSetMethod(includeNonPublic), valueCast);
#else
MethodCallExpression call = Expression.Call(instanceCast, property.SetMethod, valueCast);
#endif
return Expression.Lambda<Action<object, object>>(call, new[] {instance, value}).Compile();
}
示例15: IsInteresting
internal static bool IsInteresting(PropertyInfo pi)
{
MethodInfo getter, setter;
return pi.CanRead && pi.CanWrite &&
(getter = pi.GetGetMethod()) != null && getter.IsVirtual &&
(setter = pi.GetSetMethod()) != null && setter.IsVirtual;
}