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


C# Reflection.PropertyInfo类代码示例

本文整理汇总了C#中System.Reflection.PropertyInfo的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo类的具体用法?C# PropertyInfo怎么用?C# PropertyInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PropertyInfo类属于System.Reflection命名空间,在下文中一共展示了PropertyInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetValueFromXml

        protected override object GetValueFromXml(XElement root, XName name, PropertyInfo prop)
        {
            var isAttribute = false;

            // Check for the DeserializeAs attribute on the property
            var options = prop.GetAttribute<DeserializeAsAttribute>();

            if (options != null)
            {
                name = options.Name ?? name;
                isAttribute = options.Attribute;
            }

            if (isAttribute)
            {
                var attributeVal = GetAttributeByName(root, name);

                if (attributeVal != null)
                {
                    return attributeVal.Value;
                }
            }

            return base.GetValueFromXml(root, name, prop);
        }
开发者ID:mgulubov,项目名称:RestSharpHighQualityCodeTeamProject,代码行数:25,代码来源:XmlAttributeDeserializer.cs

示例2: PropertyToElementInit

 static ElementInit PropertyToElementInit(PropertyInfo propertyInfo, Expression instance)
 {
     return Expression.ElementInit(DictionaryAddMethod,
                                   Expression.Constant(propertyInfo.Name),
                                   Expression.Call(ToStringOrNullMethod,
                                                   Expression.Convert(Expression.Property(instance, propertyInfo), typeof(object))));
 }
开发者ID:muratbeyaztas,项目名称:Simple.Web,代码行数:7,代码来源:ObjectEx.cs

示例3: Create

        public static ConstantUpdate Create(PropertyInfo property, ConstantExpression constantExpr)
        {
            Debug.Assert(property != null, "property should not be null");
            Debug.Assert(constantExpr != null, "constantExpr should not be null");

            return new ConstantUpdate(property, constantExpr.Value);
        }
开发者ID:jefth,项目名称:EasyMongo,代码行数:7,代码来源:ConstantUpdate.cs

示例4: MvxBasePropertyInfoSourceBinding

        protected MvxBasePropertyInfoSourceBinding(object source, string propertyName)
            : base(source)
        {
            _propertyName = propertyName;

            if (Source == null)
            {
                MvxBindingTrace.Trace(
                    MvxTraceLevel.Warning,                 
                    "Unable to bind to source is null"
                    , propertyName);
                return;
            }

            _propertyInfo = source.GetType().GetProperty(propertyName);
            if (_propertyInfo == null)
            {
                MvxBindingTrace.Trace(
                    MvxTraceLevel.Warning,
                    "Unable to bind: source property source not found {0} on {1}"
                    , propertyName,
                    source.GetType().Name);
            }

            var sourceNotify = Source as INotifyPropertyChanged;
            if (sourceNotify != null)
                sourceNotify.PropertyChanged += new PropertyChangedEventHandler(SourcePropertyChanged);
        }
开发者ID:284247028,项目名称:MvvmCross,代码行数:28,代码来源:MvxBasePropertyInfoSourceBinding.cs

示例5: CreateRelationObject

        /// <summary>
        /// Creates one instance of the Relation Object from the PropertyInfo object of the reflected class
        /// </summary>
        /// <param name="propInfo"></param>
        /// <returns></returns>
        public static Relation CreateRelationObject(PropertyInfo propInfo)
        {
            Relation result = new VSPlugin.Relation();

            // get's the Relation Attribute in the class
            RelationAttribute relationAttribute = propInfo.GetCustomAttribute<RelationAttribute>();

            if (relationAttribute== null)
                return result;

            Type elementType = null;
            //we need to discover the id of the relation and if it's a collection
            if (propInfo.PropertyType.IsArray)
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetElementType();
            }
            else if(propInfo.PropertyType.IsGenericType && propInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetGenericArguments().Single();
            }
            else
                elementType = propInfo.PropertyType;

            result.Type = GetResourceType(elementType);
            result.Required = relationAttribute.Required;
            result.Requirement = relationAttribute.Requirement;
            result.Allocate = relationAttribute.Allocate.ToString();

            return result;
        }
开发者ID:lasttry,项目名称:APS.CSharp.VSPlugin,代码行数:39,代码来源:Relation.cs

示例6: CreateGetMethod

        internal static GenericGetter CreateGetMethod(Type type, PropertyInfo propertyInfo)
        {
            MethodInfo getMethod = propertyInfo.GetGetMethod();
            if (getMethod == null)
                return null;

            DynamicMethod getter = new DynamicMethod("_", typeof(object), new Type[] { typeof(object) }, type);

            ILGenerator il = getter.GetILGenerator();

            if (!type.IsClass) // structs
            {
                var lv = il.DeclareLocal(type);
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Unbox_Any, type);
                il.Emit(OpCodes.Stloc_0);
                il.Emit(OpCodes.Ldloca_S, lv);
                il.EmitCall(OpCodes.Call, getMethod, null);
                if (propertyInfo.PropertyType.IsValueType)
                    il.Emit(OpCodes.Box, propertyInfo.PropertyType);
            }
            else
            {
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Castclass, propertyInfo.DeclaringType);
                il.EmitCall(OpCodes.Callvirt, getMethod, null);
                if (propertyInfo.PropertyType.IsValueType)
                    il.Emit(OpCodes.Box, propertyInfo.PropertyType);
            }

            il.Emit(OpCodes.Ret);

            return (GenericGetter)getter.CreateDelegate(typeof(GenericGetter));
        }
开发者ID:gustafsonk,项目名称:TFS-Treemap,代码行数:34,代码来源:Reflection.cs

示例7: GetBackingFieldInternal

 //Supports getters of the form `return field;`
 private static FieldInfo GetBackingFieldInternal(PropertyInfo property)
 {
     if (property == null)
         throw new ArgumentNullException("property");
     MethodInfo getter = property.GetGetMethod(true);
     if (getter == null)
         return null;
     byte[] il = getter.GetMethodBody().GetILAsByteArray();
     if (il.Length != 7
        || il[0] != 0x02//ldarg.0
        || il[1] != 0x7b//ldfld <field>
        || il[6] != 0x2a//ret
        )
         return null;
     int metadataToken = il[2] | il[3] << 8 | il[4] << 16 | il[5] << 24;
     Type type = property.ReflectedType;
     do
     {
         foreach (FieldInfo fi in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
         {
             if (fi.MetadataToken == metadataToken)
                 return fi;
         }
         type = type.BaseType;
     } while (type != null);
     throw new Exception("Field not found");
 }
开发者ID:jorik041,项目名称:ChaosUtil,代码行数:28,代码来源:MemberFromLamda.cs

示例8: ProcessProperty

		/// <summary>
		/// Dispatches the call to the extensions.
		/// </summary>
		/// <param name="pi">The property info reflection object.</param>
		/// <param name="model">The model.</param>
		public void ProcessProperty(PropertyInfo pi, ActiveRecordModel model)
		{
			foreach(IModelBuilderExtension extension in extensions)
			{
				extension.ProcessProperty(pi, model);
			}
		}
开发者ID:pallmall,项目名称:WCell,代码行数:12,代码来源:ModelBuilderExtensionComposite.cs

示例9: GetLocalizationInfo

        private static LocalizationInfo GetLocalizationInfo(PropertyInfo prop)
        {
            var attr = prop.GetCustomAttribute<LocalizeAttribute>();
            if(attr == null)
            {
                return null;
            }
            var info = new LocalizationInfo
            {
                ResourceName = attr.ResourceName ?? (prop.DeclaringType.Name + "_" + prop.Name)
            };

            if(info.ResourceType != null)
            {
                info.ResourceType = attr.ResourceType;
            }
            else
            {
                var parent = prop.DeclaringType.GetTypeInfo().GetCustomAttribute<LocalizeAttribute>();
                if(parent == null || parent.ResourceType == null)
                {
                    throw new ArgumentException(String.Format(
                        "The property '{0}' or its parent class '{1}' must define a ResourceType in order to be localized.",
                        prop.Name, prop.DeclaringType.Name));
                }
                info.ResourceType = parent.ResourceType;
            }

            return info;
        }
开发者ID:nemec,项目名称:clipr,代码行数:30,代码来源:AttributeConverter.cs

示例10: MatchTest

 public MatchResult MatchTest(PropertyInfo property)
 {
     if (property.PropertyType.Equals(typeof(DateTime)))
         return MatchResult.Match;
     else
         return MatchResult.NotMatch;
 }
开发者ID:zealoussnow,项目名称:OneCode,代码行数:7,代码来源:DateConfigControl.cs

示例11: IsValid

        public ValidationResult IsValid(PropertyInfo propertyToValidate, object value)
        {
            // enable to be empty
            if (value == null)
                return ValidationResult.Success;

            if (!(value is DateTime))
            {
                return ValidationResult.CreateError(propertyToValidate, "Adf.Business.AttributeInRangeInvalid", propertyToValidate.Name);
            }
            //            double newValue;
            //            try
            //            {
            //                newValue = (double)value;
            //            }
            //            catch
            //            {
            //                return ValidationResult.CreateError(propertyToValidate, "Adf.Business.AttributeInRangeInvalid", propertyToValidate.Name);
            //            }

            DateTime newValue = (DateTime) value;

            if (min >= newValue || max <= newValue)
            {
                return ValidationResult.CreateError(propertyToValidate, "Adf.Business.AttributeInRangeInvalidRange", propertyToValidate.Name, min, max);
            }

            //            if (!NumberHelper.CheckRange(newValue, min, max))
            //                return ValidationResult.CreateError(propertyToValidate, "Adf.Business.AttributeInRangeInvalidRange", propertyToValidate.Name, min, max);

            return ValidationResult.Success;
        }
开发者ID:NLADP,项目名称:ADF,代码行数:32,代码来源:InSqlDateTimeRangeAttribute.cs

示例12: ProcessBelongsTo

		/// <summary>
		/// Dispatches the call to the extensions.
		/// </summary>
		/// <param name="pi">The property info reflection object.</param>
		/// <param name="belongsToModel">The belongs to model.</param>
		/// <param name="model">The model.</param>
		public void ProcessBelongsTo(PropertyInfo pi, BelongsToModel belongsToModel, ActiveRecordModel model)
		{
			foreach(IModelBuilderExtension extension in extensions)
			{
				extension.ProcessBelongsTo(pi, belongsToModel, model);
			}
		}
开发者ID:pallmall,项目名称:WCell,代码行数:13,代码来源:ModelBuilderExtensionComposite.cs

示例13: DynamicPropertyAccessor

        public DynamicPropertyAccessor(PropertyInfo propertyInfo)
        {
            // target: (object)((({TargetType})instance).{Property})

            // preparing parameter, object type
            ParameterExpression instance = Expression.Parameter(
                typeof(object), "instance");

            // ({TargetType})instance
            Expression instanceCast = Expression.Convert(
                instance, propertyInfo.ReflectedType);

            // (({TargetType})instance).{Property}
            Expression propertyAccess = Expression.Property(
                instanceCast, propertyInfo);

            // (object)((({TargetType})instance).{Property})
            UnaryExpression castPropertyValue = Expression.Convert(
                propertyAccess, typeof(object));

            // Lambda expression
            Expression<Func<object, object>> lambda =
                Expression.Lambda<Func<object, object>>(
                    castPropertyValue, instance);

            this.m_getter = lambda.Compile();

            MethodInfo setMethod = propertyInfo.GetSetMethod();
            if (setMethod != null) {
                this.m_dynamicSetter = new DynamicMethodExecutor(setMethod);
            }
        }
开发者ID:zicjin,项目名称:sharp_net,代码行数:32,代码来源:FastEval.cs

示例14: GetValueOnField

 public virtual object GetValueOnField(object valueOnDomain, object value, PropertyInfo propertyInfo)
 {
     object valueOnField = value;
     if (valueOnDomain != null && typeof (CustomEnum).IsAssignableFrom(propertyInfo.PropertyType))
         valueOnField = CustomEnum.ValueOf(propertyInfo.PropertyType, value.ToString());
     return valueOnField;
 }
开发者ID:tmandersson,项目名称:FastGTD,代码行数:7,代码来源:BricksAttribute.cs

示例15: GetPropertyInterceptors

 protected IList<IPropertyInterceptor> GetPropertyInterceptors(PropertyInfo Property)
 {
     if (this.PropertyInterceptorRegistrations.ContainsKey(Property))
         return this.PropertyInterceptorRegistrations[Property];
     else
         return null;
 }
开发者ID:robinli,项目名称:TheOrigin,代码行数:7,代码来源:DynamicProxyBase.cs


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