本文整理汇总了C#中System.Reflection.TypeInfo.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.GetProperties方法的具体用法?C# TypeInfo.GetProperties怎么用?C# TypeInfo.GetProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.GetProperties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassMetadata
internal ClassMetadata(TypeInfo typeInfo)
{
#if !DataAnnotations_Missing
var table = (TableAttribute)typeInfo.GetCustomAttributes(typeof(TableAttribute), true).SingleOrDefault();
if (table != null)
{
MappedTableName = table.Name;
MappedSchemaName = table.Schema;
}
#endif
#if Weird_Reflection
var shadowingProperties = (from p in typeInfo.DeclaredProperties where IsHidingMember(p) select p).ToList();
var propertyList = typeInfo.DeclaredProperties.ToList();
#elif TypeInfo_Is_Not_Type
var type = typeInfo.AsType();
var shadowingProperties = (from p in type.GetProperties() where IsHidingMember(p) select p).ToList();
var propertyList = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
#else
var shadowingProperties = (from p in typeInfo.GetProperties() where IsHidingMember(p) select p).ToList();
var propertyList = typeInfo.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
#endif
Func<PropertyInfo, bool> IsHidden = propertyInfo => !shadowingProperties.Contains(propertyInfo) && shadowingProperties.Any(p => p.Name == propertyInfo.Name);
Properties = new PropertyMetadataCollection(propertyList.Where(p => !IsHidden(p)).Select(p => new PropertyMetadata(p)));
//List the properties that are affected when the indicated property is modified.
foreach (var property in Properties)
foreach (CalculatedFieldAttribute fieldList in property.PropertyInfo.GetCustomAttributes(typeof(CalculatedFieldAttribute), true))
foreach (var field in fieldList.SourceProperties)
{
if (!Properties.Contains(field))
throw new InvalidOperationException(string.Format("Cannot find property {0} on type {1}. This is needed for the calculated property {2}", field, typeInfo.FullName, property.Name));
Properties[field].AddCalculatedField(property);
}
foreach (var property in Properties)
property.EndInit();
Constructors = new ConstructorMetadataCollection(typeInfo.DeclaredConstructors);
}
示例2: GetAllPublicProperties
public PropertyInfo[] GetAllPublicProperties(TypeInfo typeInfo)
{
return typeInfo.GetProperties(BindingFlags.Public | BindingFlags.Instance);
}