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


C# PropertyInfo.GetGetMethod方法代码示例

本文整理汇总了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());
			}
		}
开发者ID:RuBeArtZilla,项目名称:AZLib,代码行数:9,代码来源:GeneratorExtensions.cs

示例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;
 }
开发者ID:srndpty,项目名称:VFW,代码行数:9,代码来源:fsMetaProperty.cs

示例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();
        }
开发者ID:dbrizov,项目名称:fullserializer,代码行数:11,代码来源:fsMetaProperty.cs

示例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;
 }
开发者ID:wizardbeard,项目名称:Shielded,代码行数:7,代码来源:ProxyGen.cs

示例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);
        }
开发者ID:sebastianhaba,项目名称:api,代码行数:35,代码来源:ReflectionHelper.cs

示例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));
        }
开发者ID:Jiannan,项目名称:PlainTextSerializer,代码行数:40,代码来源:ReflectonHelper.cs

示例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);
        }
开发者ID:geobabbler,项目名称:SharpMap,代码行数:29,代码来源:PocoFeatureAttributeDefinition.cs

示例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;
        }
开发者ID:zakvdm,项目名称:Frenetic,代码行数:7,代码来源:TweakablePropertiesLoader.cs

示例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;
		}
开发者ID:jeroenheijmans,项目名称:elasticsearch-net,代码行数:28,代码来源:PropertyWalker.cs

示例10: PropertyObject

 public PropertyObject(PropertyInfo md)
     : base()
 {
     getter = md.GetGetMethod(true);
     setter = md.GetSetMethod(true);
     info = md;
 }
开发者ID:EntityFXCode,项目名称:arsenalsuite,代码行数:7,代码来源:propertyobject.cs

示例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;
 }
开发者ID:jason-roberts,项目名称:TestStack.BDDfy,代码行数:7,代码来源:StepArgument.cs

示例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);
 }
开发者ID:jemacom,项目名称:fubumvc,代码行数:7,代码来源:PropertySourceGenerator.cs

示例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;
     }
 }
开发者ID:Skycweb,项目名称:blqw-Faller,代码行数:33,代码来源:ObjectProperty.cs

示例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();
        }
开发者ID:GQHero,项目名称:TinyStorage,代码行数:26,代码来源:PropertyAccessor.cs

示例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();
 }
开发者ID:kekekeks,项目名称:hal-json-net,代码行数:7,代码来源:AttributeConfigurationResolver.cs


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