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


C# IReflect.GetProperties方法代码示例

本文整理汇总了C#中IReflect.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# IReflect.GetProperties方法的具体用法?C# IReflect.GetProperties怎么用?C# IReflect.GetProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IReflect的用法示例。


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

示例1: BuildLoggerInjectors

        private static IEnumerable<Action<IComponentContext, object>> BuildLoggerInjectors(IReflect componentType)
        {
            // look for settable properties of type "ILogger"
            var loggerProperties = componentType
                .GetProperties(BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance)
                .Select(p => new
                {
                    PropertyInfo = p,
                    p.PropertyType,
                    IndexParameters = p.GetIndexParameters(),
                    Accessors = p.GetAccessors(false)
                })
                // must be a logger
                .Where(x => x.PropertyType == typeof(ILogger))
                // must not be an indexer
                .Where(x => x.IndexParameters.Count() == 0)
                // must have get/set, or only set
                .Where(x => x.Accessors.Length != 1 || x.Accessors[0].ReturnType == typeof(void));

            // return an IEnumerable of actions that resolve a logger and assign the property
            return loggerProperties
                   .Select(entry => entry.PropertyInfo)
                   .Select(propertyInfo => (Action<IComponentContext, object>)((ctx, instance) =>
                   {
                       var propertyValue = ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType));
                       propertyInfo.SetValue(instance, propertyValue, null);
                   }));
        }
开发者ID:mikkoj,项目名称:LunchCrawler,代码行数:28,代码来源:LoggingInjectModule.cs

示例2: FormatPropertiesResolver

 public FormatPropertiesResolver(IReflect type, IPropertyFormatInfoProvider formatInfoProvider)
 {
     this.formatInfoProvider = formatInfoProvider;
     PropertiesFormat =
         type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
             .Where(prop => prop.CanRead)
             .Select(ConvertToPropertyFormat)
             .Where(pform => pform != null);
 }
开发者ID:black-virus,项目名称:local-nuget,代码行数:9,代码来源:FormatPropertiesResolver.cs

示例3: FindUserProperty

 private static PropertyInfo FindUserProperty(IReflect type)
 {
     //寻找类型为 "Localizer" 并且具有set方法的属性。
     return type
         .GetProperties(BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance)
         .Where(x => x.PropertyType == typeof(Localizer)) //必须是一个本地化委托
         .Where(x => !x.GetIndexParameters().Any()) //没有索引器
         .FirstOrDefault(x => x.GetAccessors(false).Length != 1 || x.GetAccessors(false)[0].ReturnType == typeof(void)); //必须具有set方法。
 }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:9,代码来源:LocalizationModule.cs

示例4: WriteObject

        void WriteObject(TextWriter writer, object value, IReflect type)
        {
            foreach (var property in type
                .GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var propertyValue = property.GetValue(value, new object[] { });

                WriteTag(writer, propertyValue, property, null);
            }
        }
开发者ID:MrAntix,项目名称:Serializing,代码行数:10,代码来源:POXSerializer.serialize.cs

示例5: injectMembers

		private void injectMembers(IReflect type, object instance)
		{
			var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
				.Where(x => x.CanWrite);
			foreach (var propertyInfo in properties)
			{
				propertyInfo.SetValue(instance, _container.Resolve(propertyInfo.PropertyType), null);
			}
			var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
			foreach (var fieldsInfo in fields)
			{
				fieldsInfo.SetValue(instance, _container.Resolve(fieldsInfo.FieldType));
			}
		}
开发者ID:Teleopti,项目名称:Stardust,代码行数:14,代码来源:BaseTestsAttribute.cs

示例6: BuildLoggerInjectors

        private IEnumerable<Action<IComponentContext, object>> BuildLoggerInjectors(IReflect componentType)
        {
            //寻找类型为 "ILogger" 并且具有set方法的属性。
            var loggerProperties = componentType
                .GetProperties(BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance)
                .Select(p => new
                {
                    PropertyInfo = p,
                    p.PropertyType,
                    IndexParameters = p.GetIndexParameters(),
                    Accessors = p.GetAccessors(false)
                })
                .Where(x => x.PropertyType == typeof(ILogger)) //必须是一个日志记录器
                .Where(x => !x.IndexParameters.Any()) //没有索引器
                .Where(x => x.Accessors.Length != 1 || x.Accessors[0].ReturnType == typeof(void)); //必须具有set方法。

            return loggerProperties.Select(entry => entry.PropertyInfo).Select(propertyInfo => (Action<IComponentContext, object>)((ctx, instance) =>
            {
                var component = componentType.ToString();
                var logger = _loggerCache.GetOrAdd(component, key => ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType)));
                propertyInfo.SetValue(instance, logger, null);
            }));
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:23,代码来源:LoggingModule.cs

示例7: GetIndexablePropertyInfos

 private PropertyInfo[] GetIndexablePropertyInfos(IReflect type)
 {
     return type.GetProperties(PropertyBindingFlags);
 }
开发者ID:kukubadze,项目名称:SisoDb-Provider,代码行数:4,代码来源:StructureTypeReflecter.cs

示例8: GetIndexablePropertyInfos

 private PropertyInfo[] GetIndexablePropertyInfos(IReflect type, bool includeContainedStructureMembers)
 {
     return includeContainedStructureMembers
         ? type.GetProperties(PropertyBindingFlags)
         : type.GetProperties(PropertyBindingFlags).Where(p => HasIdProperty(p.PropertyType) == false).ToArray();
 }
开发者ID:danielwertheim,项目名称:PineCone,代码行数:6,代码来源:StructureTypeReflecter.cs

示例9: GetProxyProperties

 private static IEnumerable<PropertyInfo> GetProxyProperties(IReflect hostType)
 {
     return hostType
         .GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty);
 }
开发者ID:Yitzchok,项目名称:Fohjin,代码行数:5,代码来源:IEventProvider.cs

示例10: GetPropertiesWithAttributes

        private static IEnumerable<KeyValuePair<PropertyInfo, DocumentTypePropertyAttribute>> GetPropertiesWithAttributes(IReflect type)
        {
            var privateOrPublicInstanceProperties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var propertiesWithPropertyAttributes = privateOrPublicInstanceProperties.Where(propertyInfo => HasAttribute(propertyInfo, typeof(DocumentTypePropertyAttribute)));

            var propertyAttributeMapping = new Dictionary<PropertyInfo, DocumentTypePropertyAttribute>();

            foreach (var property in propertiesWithPropertyAttributes)
            {
                var propertyAttribute = (DocumentTypePropertyAttribute)property.GetCustomAttributes(true).SingleOrDefault(attribute => attribute is DocumentTypePropertyAttribute);
                if (propertyAttribute != null && !propertyAttributeMapping.ContainsKey(property))
                {
                    propertyAttributeMapping.Add(property, propertyAttribute);
                }
            }
            return propertyAttributeMapping;
        }
开发者ID:enkelmedia,项目名称:UmbraCodeFirst,代码行数:17,代码来源:DocumentTypeSynchronizer.cs

示例11: GetProperties

		private static IEnumerable<string> GetProperties(IReflect myType, BindingFlags flags)
		{
			var properties = myType.GetProperties(flags);
			foreach (var propertyInfo in properties)
			{
				var type = ToPrettyString(propertyInfo.PropertyType);
				if (!returnTypeDictionary.ContainsKey(type))
					returnTypeDictionary[type] = new List<string>();
				returnTypeDictionary[type].Add(propertyInfo.Name);
			}
			return properties.Select(x => x.Name).Distinct();
		}
开发者ID:andgein,项目名称:uLearn,代码行数:12,代码来源:CsCompleterGenerator.cs

示例12: WriteToInstance

        private static void WriteToInstance(object instance, IReflect type, XContainer xContainer)
        {
            foreach (var pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var propertyType = pi.PropertyType;

                if (propertyType.IsValueType())
                {
                    var child = xContainer.Element(pi.Name);
                    if (child == null) continue;
                    if (pi.GetSetMethod(true) == null) continue;
                    var value = XmlValueConverter.Convert(child.Value, propertyType);
                    pi.SetValue(instance, value, null);
                    continue;
                }

                if (propertyType.IsClass())
                {
                    var propertyInstance = FormatterServices.GetUninitializedObject(propertyType);
                    pi.SetValue(instance, propertyInstance, null);
                    WriteToInstance(propertyInstance, propertyType, xContainer.Element(pi.Name));
                    continue;
                }

                if (propertyType.IsCollection())
                {
                    var current = xContainer.Element(pi.Name);
                    if (current == null) return;
                    var itemType = typeof(object);

                    if (propertyType.IsGenericType)
                    {
                        itemType = propertyType.GetGenericArguments()[0];
                    }

                    var list = itemType.CreateGenericList();

                    foreach (var item in current.Elements())
                    {
                        var itemInstance = FormatterServices.GetUninitializedObject(itemType);
                        WriteToInstance(itemInstance, itemType, item);
                        list.Add(itemInstance);
                    }

                    pi.SetValue(instance, list, null);
                }
            }
        }
开发者ID:Zapote,项目名称:EzBus,代码行数:48,代码来源:XmlMessageSerializer.cs

示例13: GetTestSourcePropertiesFrom

 private static IEnumerable<PropertyInfo> GetTestSourcePropertiesFrom(IReflect type)
 {
     return type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(IsTestSource);
 }
开发者ID:WalkingDisaster,项目名称:Lingual,代码行数:4,代码来源:LingualAddin.cs

示例14: GetProperties

 private static IEnumerable<PropertyInfo> GetProperties(IReflect type)
 {
     return type.GetProperties(Flags);
 }
开发者ID:Tdue21,项目名称:teamcitycsharprunner,代码行数:4,代码来源:AbstractObjectVisitor.cs

示例15: GetTombstonedProperties

 private static List<PropertyInfo> GetTombstonedProperties(IReflect viewModelType)
 {
     var propertyInfos = viewModelType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
     var properties = new List<PropertyInfo>(propertyInfos).Where(x => x.IsDefined(typeof (TombstonedAttribute), true)).ToList();
     return properties;
 }
开发者ID:dotcypress,项目名称:Vermeil,代码行数:6,代码来源:TombstoneManager.cs


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