本文整理汇总了C#中System.Reflection.MemberInfo.MemberName方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.MemberName方法的具体用法?C# MemberInfo.MemberName怎么用?C# MemberInfo.MemberName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.MemberName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExpansion
static LambdaExpression GetExpansion(MemberInfo mi)
{
ExpressionFieldAttribute efa = mi.GetCustomAttribute<ExpressionFieldAttribute>();
if (efa == null)
return null;
if (efa.Name == "auto")
throw new InvalidOperationException($"The {nameof(ExpressionFieldAttribute)} for {mi.DeclaringType.TypeName()}.{mi.MemberName()} has the default value 'auto'.\r\nMaybe Signum.MSBuildTask is not running in assemby {mi.DeclaringType.Assembly.GetName().Name}?");
Type type = mi.DeclaringType;
FieldInfo fi = type.GetField(efa.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (fi == null)
throw new InvalidOperationException("Expression field '{0}' not found on '{1}'".FormatWith(efa.Name, type.TypeName()));
var obj = fi.GetValue(null);
if (obj == null)
throw new InvalidOperationException("Expression field '{0}' is null".FormatWith(efa.Name));
var result = obj as LambdaExpression;
if (result == null)
throw new InvalidOperationException("Expression field '{0}' does not contain a lambda expression".FormatWith(efa.Name, type.TypeName()));
return result;
}