本文整理汇总了C#中System.Reflection.MemberInfo.TryGetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.TryGetAttribute方法的具体用法?C# MemberInfo.TryGetAttribute怎么用?C# MemberInfo.TryGetAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.TryGetAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUniqueProperties
internal static void SetUniqueProperties(MemberInfo memberInfo, Action<UniqueAttribute> makeUnique)
{
var uniqueAttribute = memberInfo.TryGetAttribute<UniqueAttribute>();
if (uniqueAttribute == null)
return;
makeUnique(uniqueAttribute);
}
示例2: TryGetProperty
bool TryGetProperty(MemberInfo memberInfo, out EntityProperty property)
{
EditorPropertyAttribute propertyAttribute;
if (memberInfo.TryGetAttribute(out propertyAttribute))
{
Type memberType = null;
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
memberType = (memberInfo as FieldInfo).FieldType;
break;
case MemberTypes.Property:
memberType = (memberInfo as PropertyInfo).PropertyType;
break;
}
var limits = new EntityPropertyLimits(propertyAttribute.Min, propertyAttribute.Max);
property = new EntityProperty(memberInfo.Name, propertyAttribute.Description, Entity.GetEditorType(memberType, propertyAttribute.Type), limits, propertyAttribute.Flags);
return true;
}
property = new EntityProperty();
return false;
}
示例3: TryGetEntityProperty
bool TryGetEntityProperty(MemberInfo memberInfo, ref Dictionary<string, List<EditorProperty>> folders)
{
EditorPropertyAttribute propertyAttribute;
if (memberInfo.TryGetAttribute(out propertyAttribute))
{
Type memberType = null;
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
memberType = (memberInfo as FieldInfo).FieldType;
break;
case MemberTypes.Property:
memberType = (memberInfo as PropertyInfo).PropertyType;
break;
}
var limits = new EditorPropertyLimits(propertyAttribute.Min, propertyAttribute.Max);
var property = new EditorProperty(propertyAttribute.Name ?? memberInfo.Name, propertyAttribute.Description, Entity.GetEditorType(memberType, propertyAttribute.Type), limits, propertyAttribute.Flags);
if (propertyAttribute.Folder == null)
propertyAttribute.Folder = "Default";
if (!folders.ContainsKey(propertyAttribute.Folder))
folders.Add(propertyAttribute.Folder, new List<EditorProperty>());
folders[propertyAttribute.Folder].Add(property);
return true;
}
return false;
}