本文整理汇总了C#中System.Reflection.MemberInfo.SingleAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.SingleAttribute方法的具体用法?C# MemberInfo.SingleAttribute怎么用?C# MemberInfo.SingleAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.SingleAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefaultMemberDescription
internal static string DefaultMemberDescription(MemberInfo m)
{
return m.SingleAttribute<DescriptionAttribute>().Try(t => t.Description) ?? m.Name.NiceName();
}
示例2: GetExpansion
static LambdaExpression GetExpansion(MemberInfo mi)
{
ExpressionFieldAttribute efa = mi.SingleAttribute<ExpressionFieldAttribute>();
string name = efa.Try(a => a.Name) ?? mi.Name + "Expression";
Type type = mi.DeclaringType;
FieldInfo fi = type.GetField(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (fi != null)
return fi.GetValue(null) as LambdaExpression;
else if (efa != null)
throw new InvalidOperationException("Expression field '{0}' not found on '{1}'".Formato(name, type.TypeName()));
return null;
}
示例3: GetMemberNiceName
static string GetMemberNiceName(MemberInfo memberInfo)
{
var cc = CultureInfo.CurrentUICulture;
var type = memberInfo.DeclaringType;
if (LocalizedAssembly.GetDefaultAssemblyCulture(type.Assembly) == null)
{
if (type == typeof(DayOfWeek))
return CultureInfo.CurrentCulture.DateTimeFormat.DayNames[(int)((FieldInfo)memberInfo).GetValue(null)];
return memberInfo.SingleAttribute<DescriptionAttribute>().Try(a => a.Description) ?? memberInfo.Name.NiceName();
}
var result = Fallback(type, lt => lt.Members.TryGetC(memberInfo.Name));
if (result != null)
return result;
return result;
}