本文整理汇总了C#中System.Reflection.PropertyInfo.GetGetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetGetMethod方法的具体用法?C# PropertyInfo.GetGetMethod怎么用?C# PropertyInfo.GetGetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetGetMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadPropertyValue
public static void LoadPropertyValue(this ILGenerator il, PropertyInfo property, LocalBuilder target) {
if (target.LocalType.IsValueType || target.LocalType.IsNullable()) {
il.LoadLocalAddress(target);
il.Call(property.GetGetMethod());
} else {
il.LoadLocal(target);
il.CallVirt(property.GetGetMethod());
}
}
示例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: 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();
}
示例4: 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;
}
示例5: IsMatch
private static bool IsMatch(PropertyInfo propertyInfo, BindingFlags flags)
{
// this methods is heavily used during reflection, so we have traded
// readablility for performance.
var mainMethod = propertyInfo.GetGetMethod() ?? propertyInfo.GetSetMethod();
if (mainMethod == null)
return false;
if (flags == Type.BindFlags.AllMembers || flags == Type.BindFlags.DeclaredMembers)
return true;
bool incStatic = (flags & BindingFlags.Static) == BindingFlags.Static;
bool incInstance = (flags & BindingFlags.Instance) == BindingFlags.Instance;
if (incInstance == incStatic && !incInstance)
return false;
if (incInstance != incStatic)
{
bool isStatic = mainMethod.IsStatic;
if (!((incStatic && isStatic) || (incInstance && !isStatic)))
return false;
}
bool incPublic = (flags & BindingFlags.Public) == BindingFlags.Public;
bool incNonPublic = (flags & BindingFlags.NonPublic) == BindingFlags.NonPublic;
if (incPublic == incNonPublic)
return incPublic;
bool isPublic = mainMethod.IsPublic;
return (incPublic && isPublic) || (incNonPublic && !isPublic);
}
示例6: CreateGetMethod
/// <summary>
/// Creates a dynamic getter for the property
/// </summary>
/// <param name="propertyInfo"></param>
/// <returns></returns>
public static GenericGetter CreateGetMethod(PropertyInfo propertyInfo)
{
/*
* If there's no getter return null
*/
MethodInfo getMethod = propertyInfo.GetGetMethod();
if (getMethod == null)
return null;
/*
* Create the dynamic method
*/
Type[] arguments = new Type[1];
arguments[0] = typeof(object);
DynamicMethod getter = new DynamicMethod(
String.Concat("_Get", propertyInfo.Name, "_"),
typeof(object), arguments, propertyInfo.DeclaringType,false);
ILGenerator generator = getter.GetILGenerator();
generator.DeclareLocal(typeof(object));
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Castclass, propertyInfo.DeclaringType);
generator.EmitCall(OpCodes.Callvirt, getMethod, null);
if (!propertyInfo.PropertyType.IsClass)
generator.Emit(OpCodes.Box, propertyInfo.PropertyType);
generator.Emit(OpCodes.Ret);
/*
* Create the delegate and return it
*/
return (GenericGetter)getter.CreateDelegate(typeof(GenericGetter));
}
示例7: 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);
}
示例8: 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;
}
示例9: GetProperty
private IProperty GetProperty(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
{
var property = _visitor.Visit(propertyInfo, attribute);
if (property != null)
return property;
if (propertyInfo.GetGetMethod().IsStatic)
return null;
if (attribute != null)
property = attribute;
else
property = InferProperty(propertyInfo.PropertyType);
var objectProperty = property as IObjectProperty;
if (objectProperty != null)
{
var type = GetUnderlyingType(propertyInfo.PropertyType);
var seenTypes = new ConcurrentDictionary<Type, int>(_seenTypes);
seenTypes.AddOrUpdate(type, 0, (t, i) => ++i);
var walker = new PropertyWalker(type, _visitor, _maxRecursion, seenTypes);
objectProperty.Properties = walker.GetProperties(seenTypes, _maxRecursion);
}
_visitor.Visit(property, propertyInfo, attribute);
return property;
}
示例10: PropertyObject
public PropertyObject(PropertyInfo md)
: base()
{
getter = md.GetGetMethod(true);
setter = md.GetSetMethod(true);
info = md;
}
示例11: StepArgument
public StepArgument(PropertyInfo member, object declaringObject)
{
Name = member.Name;
_get = () => member.GetGetMethod(true).Invoke(declaringObject, null);
_set = o => member.GetSetMethod(true).Invoke(declaringObject, new[] { o });
ArgumentType = member.PropertyType;
}
示例12: SourceFor
public string SourceFor(PropertyInfo property)
{
return string.Format("{0} {1} {2} {{ get; set; }}",
property.GetGetMethod().IsPublic ? "public" : "internal",
property.PropertyType.Name,
property.Name);
}
示例13: 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;
}
}
示例14: InitializeGet
private void InitializeGet(PropertyInfo propertyInfo)
{
if (!propertyInfo.CanRead) return;
// Target: (Object)(((TInstance)instance).Property)
// preparing parameter, Object type
ParameterExpression instance = Expression.Parameter(typeof (Object), "instance");
// non-instance for static method, or ((TInstance)instance)
UnaryExpression instanceCast = propertyInfo.GetGetMethod(true).IsStatic
? null
: Expression.Convert(instance, propertyInfo.ReflectedType);
// ((TInstance)instance).Property
MemberExpression propertyAccess = Expression.Property(instanceCast, propertyInfo);
// (Object)(((TInstance)instance).Property)
UnaryExpression castPropertyValue = Expression.Convert(propertyAccess, typeof (Object));
// Lambda expression
Expression<Func<object, object>> lambda = Expression.Lambda<Func<Object, Object>>(castPropertyValue,
instance);
getter = lambda.Compile();
}
示例15: CreateGetter
static Func<object, object> CreateGetter(Type t, PropertyInfo property)
{
var arg = Expression.Parameter(typeof(object), "obj");
var target = Expression.Convert(arg, t);
var getProp = Expression.Convert(Expression.Call(target, property.GetGetMethod(true)), typeof (object));
return Expression.Lambda<Func<object, object>>(getProp, arg).Compile();
}