• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Reflection.PropertyInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Get

 public static PropertyAccessor Get(PropertyInfo propertyInfo)
 {
     PropertyAccessor propertyAccessor = null;
     try {
         propertyAccessorsCacheLock.AcquireReaderLock(-1);
         if (propertyAccessorsCache.ContainsKey(propertyInfo)) {
             return (PropertyAccessor)propertyAccessorsCache[propertyInfo];
         }
     }
     finally {
         propertyAccessorsCacheLock.ReleaseReaderLock();
     }
     try {
         propertyAccessorsCacheLock.AcquireWriterLock(-1);
         if (propertyAccessorsCache.ContainsKey(propertyInfo)) {
             return (PropertyAccessor)propertyAccessorsCache[propertyInfo];
         }
         propertyAccessor = NewInstance(propertyInfo);
         propertyAccessorsCache[propertyInfo] = propertyAccessor;
     }
     finally {
         propertyAccessorsCacheLock.ReleaseWriterLock();
     }
     return propertyAccessor;
 }
开发者ID:JesonRen,项目名称:hprose,代码行数:25,代码来源:PropertyAccessor.cs


示例17: GetDefaultType

        private TypeReference GetDefaultType(PropertyInfo property)
        {
            if (IsSqlTimestamp(property))
                return new TypeReference("BinaryBlob");

            return new TypeReference(property.PropertyType);
        }
开发者ID:playtime,项目名称:fluent-nhibernate,代码行数:7,代码来源:AutoMapVersion.cs


示例18: Save

		public void Save(object obj, XmlWriter writer)
		{
			Type t = obj.GetType();
		
//			writer.WriteStartElement(GetTypeName(t));
//			System.Console.WriteLine("\tSave <{0}>",GetTypeName(t));
			                        
			writer.WriteStartElement(obj.GetType().Name);
			
			PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(obj);
			PropertyInfo [] propertyInfos = new PropertyInfo[properties.Count];
			
			for (int i = 0;i < properties.Count ; i ++){
				propertyInfos[i] = t.GetProperty(properties[i].Name);
			}
			
			foreach (PropertyInfo info in propertyInfos) {
				if (info ==  null){
					continue;
				}
				if (!info.CanRead) continue;
				
				if (info.GetCustomAttributes(typeof(XmlIgnoreAttribute), true).Length != 0) continue;
				object val = info.GetValue(obj, null);
				if (val == null) continue;
				if (val is ICollection) {
//					PropertyInfo pinfo = t.GetProperty(info.Name);
//					Console.WriteLine("pinfo {0}",pinfo.Name);
					if (info.Name.StartsWith("Contr")) {
						writer.WriteStartElement("Items");
					} else {
					writer.WriteStartElement(info.Name);
					}
					foreach (object element in (ICollection)val) {
						Save(element, writer);
					}
					
					writer.WriteEndElement();
				} else {
					if (!info.CanWrite) continue;
				
					TypeConverter c = TypeDescriptor.GetConverter(info.PropertyType);
					if (c.CanConvertFrom(typeof(string)) && c.CanConvertTo(typeof(string))) {
						try {
							writer.WriteElementString(info.Name, c.ConvertToInvariantString(val));
						} catch (Exception ex) {
							writer.WriteComment(ex.ToString());
						}
					} else if (info.PropertyType == typeof(Type)) {
						writer.WriteElementString(info.Name, ((Type)val).AssemblyQualifiedName);
					} else {
//						System.Diagnostics.Trace.WriteLine("Serialize Pagelayout");
//						writer.WriteStartElement(info.Name);
//						Save(val, writer);
//						writer.WriteEndElement();
					}
				}
			}
			writer.WriteEndElement();
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:60,代码来源:MycroWriter.cs


示例19: Configure

 /// <summary>
 /// Configures the specified property info.
 /// </summary>
 /// <param name="propertyInfo">The property info.</param>
 /// <param name="config">The config.</param>
 public void Configure(PropertyInfo propertyInfo, SitecoreInfoConfiguration config)
 {
     config.Type = Type;
     config.UrlOptions = UrlOptions;
     config.MediaUrlOptions = MediaUrlOptions;
     base.Configure(propertyInfo, config);
 }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:12,代码来源:SitecoreInfoAttribute.cs


示例20: OptionPropertyValue

 public OptionPropertyValue(PropertyInfo propertyInfo, object owner)
 {
     _propertyInfo = propertyInfo;
     _owner = owner;
     _displayName = _propertyInfo.GetCustomAttribute<DisplayNameAttribute>();
     _description = _propertyInfo.GetCustomAttribute<DescriptionAttribute>();
 }
开发者ID:roycornelissen,项目名称:ServiceInsight,代码行数:7,代码来源:OptionPropertyValue.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Reflection.RuntimeFieldInfo类代码示例发布时间:2022-05-26
下一篇:
C# Reflection.ParameterModifier类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap