本文整理汇总了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);
}));
}
示例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);
}
示例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方法。
}
示例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);
}
}
示例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));
}
}
示例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);
}));
}
示例7: GetIndexablePropertyInfos
private PropertyInfo[] GetIndexablePropertyInfos(IReflect type)
{
return type.GetProperties(PropertyBindingFlags);
}
示例8: GetIndexablePropertyInfos
private PropertyInfo[] GetIndexablePropertyInfos(IReflect type, bool includeContainedStructureMembers)
{
return includeContainedStructureMembers
? type.GetProperties(PropertyBindingFlags)
: type.GetProperties(PropertyBindingFlags).Where(p => HasIdProperty(p.PropertyType) == false).ToArray();
}
示例9: GetProxyProperties
private static IEnumerable<PropertyInfo> GetProxyProperties(IReflect hostType)
{
return hostType
.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty);
}
示例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;
}
示例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();
}
示例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);
}
}
}
示例13: GetTestSourcePropertiesFrom
private static IEnumerable<PropertyInfo> GetTestSourcePropertiesFrom(IReflect type)
{
return type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(IsTestSource);
}
示例14: GetProperties
private static IEnumerable<PropertyInfo> GetProperties(IReflect type)
{
return type.GetProperties(Flags);
}
示例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;
}