コード例 #1
0
        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;
        }