FromException() публичный статический Метод

Creates a new ErrorInfo which represents an exception that should be thrown.
public static FromException ( Expression exceptionValue ) : ErrorInfo
exceptionValue System.Linq.Expressions.Expression
Результат ErrorInfo
Пример #1
0
        private static ErrorInfo MakeIncorrectArgumentCountError(BindingTarget target)
        {
            int minArgs = Int32.MaxValue;
            int maxArgs = Int32.MinValue;

            foreach (int argCnt in target.ExpectedArgumentCount)
            {
                minArgs = System.Math.Min(minArgs, argCnt);
                maxArgs = System.Math.Max(maxArgs, argCnt);
            }

            return(ErrorInfo.FromException(
                       Ast.Call(
                           typeof(BinderOps).GetMethod("TypeErrorForIncorrectArgumentCount", new Type[] {
                typeof(string), typeof(int), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(bool)
            }),
                           Ast.Constant(target.Name, typeof(string)), // name
                           Ast.Constant(minArgs),                     // min formal normal arg cnt
                           Ast.Constant(maxArgs),                     // max formal normal arg cnt
                           Ast.Constant(0),                           // default cnt
                           Ast.Constant(target.ActualArgumentCount),  // args provided
                           Ast.Constant(false),                       // hasArgList
                           Ast.Constant(false)                        // kwargs provided
                           )
                       ));
        }
Пример #2
0
        private ErrorInfo MakeAmbiguousCallError(BindingTarget target)
        {
            StringBuilder sb         = new StringBuilder("Multiple targets could match: ");
            string        outerComma = "";

            foreach (MethodTarget mt in target.AmbiguousMatches)
            {
                Type[] types      = mt.GetParameterTypes();
                string innerComma = "";

                sb.Append(outerComma);
                sb.Append(target.Name);
                sb.Append('(');
                foreach (Type t in types)
                {
                    sb.Append(innerComma);
                    sb.Append(GetTypeName(t));
                    innerComma = ", ";
                }

                sb.Append(')');
                outerComma = ", ";
            }

            return(ErrorInfo.FromException(
                       Ast.Call(
                           typeof(BinderOps).GetMethod("SimpleTypeError"),
                           Ast.Constant(sb.ToString(), typeof(string))
                           )
                       ));
        }
Пример #3
0
 private ErrorInfo MakeInvalidSplatteeError(BindingTarget target) {
     return ErrorInfo.FromException(
         Ast.Call(typeof(BinderOps).GetMethod("InvalidSplatteeError"), 
             AstUtils.Constant(target.Name),
             AstUtils.Constant(Binder.GetTypeName(_invalidSplattee.GetLimitType()))
         )
     );
 }
Пример #4
0
 /// <summary>
 /// Provides a way for the binder to provide a custom error message when lookup fails.  Just
 /// doing this for the time being until we get a more robust error return mechanism.
 ///
 /// Deprecated, use the non-generic version instead
 /// </summary>
 public virtual ErrorInfo MakeMissingMemberError(Type type, DynamicMetaObject self, string name)
 {
     return(ErrorInfo.FromException(
                Expression.New(
                    typeof(MissingMemberException).GetConstructor(new[] { typeof(string) }),
                    AstUtils.Constant(name)
                    )
                ));
 }
Пример #5
0
 public virtual ErrorInfo MakeContainsGenericParametersError(MemberTracker tracker)
 {
     return(ErrorInfo.FromException(
                Expression.New(
                    typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) }),
                    AstUtils.Constant(Strings.InvalidOperation_ContainsGenericParameters(tracker.DeclaringType.Name, tracker.Name))
                    )
                ));
 }
Пример #6
0
 public virtual ErrorInfo MakeGenericAccessError(MemberTracker info)
 {
     return(ErrorInfo.FromException(
                Expression.New(
                    typeof(MemberAccessException).GetConstructor(new[] { typeof(string) }),
                    AstUtils.Constant(info.Name)
                    )
                ));
 }
Пример #7
0
 public virtual ErrorInfo MakeMissingMemberErrorInfo(Type type, string name)
 {
     return(ErrorInfo.FromException(
                Ast.Ast.New(
                    typeof(MissingMemberException).GetConstructor(new Type[] { typeof(string) }),
                    Ast.Ast.Constant(name)
                    )
                ));
 }
Пример #8
0
 /// <summary>
 /// Provides a way for the binder to provide a custom error message when lookup fails.  Just
 /// doing this for the time being until we get a more robust error return mechanism.
 /// </summary>
 public virtual ErrorInfo MakeReadOnlyMemberError(Type type, string name)
 {
     return(ErrorInfo.FromException(
                Expression.New(
                    typeof(MissingMemberException).GetConstructor(new Type[] { typeof(string) }),
                    AstUtils.Constant(name)
                    )
                ));
 }
Пример #9
0
 public virtual ErrorInfo MakeConversionError(Type toType, Expression value)
 {
     return(ErrorInfo.FromException(
                Expression.Call(
                    new Func <Type, object, Exception>(ScriptingRuntimeHelpers.CannotConvertError).GetMethodInfo(),
                    AstUtils.Constant(toType),
                    AstUtils.Convert(value, typeof(object))
                    )
                ));
 }
Пример #10
0
 public virtual ErrorInfo MakeConversionError(Type toType, Expression value)
 {
     return(ErrorInfo.FromException(
                Ast.Ast.Call(
                    typeof(RuntimeHelpers).GetMethod("CannotConvertError"),
                    Ast.Ast.RuntimeConstant(toType),
                    value
                    )
                ));
 }
Пример #11
0
 public virtual ErrorInfo MakeInvalidParametersError(string name, int expectedParams, params Expression[] args)
 {
     return(ErrorInfo.FromException(
                Ast.Ast.Call(
                    typeof(RuntimeHelpers).GetMethod("TypeErrorForIncorrectArgumentCount", new Type[] { typeof(string), typeof(int), typeof(int) }),
                    Ast.Ast.Constant(name),
                    Ast.Ast.Constant(args.Length),
                    Ast.Ast.Constant(expectedParams)
                    )
                ));
 }
Пример #12
0
 public virtual ErrorInfo MakeSetValueTypeFieldError(FieldTracker field, DynamicMetaObject instance, DynamicMetaObject value)
 {
     return(ErrorInfo.FromException(
                Expression.Throw(
                    Expression.New(
                        typeof(ArgumentException).GetConstructor(new[] { typeof(string) }),
                        AstUtils.Constant("cannot assign to value types")
                        ),
                    typeof(object)
                    )
                ));
 }
Пример #13
0
 private DynamicMetaObject MakeCannotCallRule(DynamicMetaObject self, Type type) {
     return MakeError(
         ErrorInfo.FromException(
             Expression.New(
                 typeof(ArgumentTypeException).GetConstructor(new Type[] { typeof(string) }),
                 AstUtils.Constant(GetTypeName(type) + " is not callable")
             )
         ),
         self.Restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(self.Expression, type)),
         typeof(object)
     );
 }
Пример #14
0
 private MetaObject MakeCannotCallRule(MetaObject self, Type type)
 {
     return(MakeError(
                ErrorInfo.FromException(
                    Ast.New(
                        typeof(ArgumentTypeException).GetConstructor(new Type[] { typeof(string) }),
                        Ast.Constant(type.Name + " is not callable")
                        )
                    ),
                self.Restrictions.Merge(Restrictions.GetTypeRestriction(self.Expression, type))
                ));
 }
Пример #15
0
 public virtual ErrorInfo MakeConversionError(Type toType, Expression value)
 {
     return(ErrorInfo.FromException(
                Expression.Call(
                    typeof(ScriptingRuntimeHelpers).GetMethod("CannotConvertError"),
                    Expression.Constant(toType),
                    Expression.Convert(
                        value,
                        typeof(object)
                        )
                    )
                ));
 }
Пример #16
0
        /// <summary>
        /// Creates an ErrorInfo object when a static property is accessed from an instance member.  The default behavior is throw
        /// an exception indicating that static members properties be accessed via an instance.  Languages can override this to
        /// customize the exception, message, or to produce an ErrorInfo object which reads or writes to the property being accessed.
        /// </summary>
        /// <param name="tracker">The static property being accessed through an instance</param>
        /// <param name="isAssignment">True if the user is assigning to the property, false if the user is reading from the property</param>
        /// <param name="parameters">The parameters being used to access the property.  This includes the instance as the first entry, any index parameters, and the
        /// value being assigned as the last entry if isAssignment is true.</param>
        /// <returns></returns>
        public virtual ErrorInfo MakeStaticPropertyInstanceAccessError(PropertyTracker tracker, bool isAssignment, IList <DynamicMetaObject> parameters)
        {
            ContractUtils.RequiresNotNull(tracker, "tracker");
            ContractUtils.Requires(tracker.IsStatic, "tracker", Strings.ExpectedStaticProperty);
            ContractUtils.RequiresNotNull(parameters, "parameters");
            ContractUtils.RequiresNotNullItems(parameters, "parameters");

            string message = isAssignment ? Strings.StaticAssignmentFromInstanceError(tracker.Name, tracker.DeclaringType.Name) :
                             Strings.StaticAccessFromInstanceError(tracker.Name, tracker.DeclaringType.Name);

            return(ErrorInfo.FromException(
                       Expression.New(
                           typeof(MissingMemberException).GetConstructor(new[] { typeof(string) }),
                           AstUtils.Constant(message)
                           )
                       ));
        }
Пример #17
0
        private ErrorInfo MakeCallFailureError(BindingTarget target)
        {
            foreach (CallFailure cf in target.CallFailures)
            {
                switch (cf.Reason)
                {
                case CallFailureReason.ConversionFailure:
                    foreach (ConversionResult cr in cf.ConversionResults)
                    {
                        if (cr.Failed)
                        {
                            return(ErrorInfo.FromException(
                                       Ast.Call(
                                           typeof(BinderOps).GetMethod("SimpleTypeError"),
                                           Ast.Constant(String.Format("expected {0}, got {1}", GetTypeName(cr.To), GetTypeName(cr.From)))
                                           )
                                       ));
                        }
                    }
                    break;

                case CallFailureReason.DuplicateKeyword:
                    return(ErrorInfo.FromException(
                               Ast.Call(
                                   typeof(BinderOps).GetMethod("TypeErrorForDuplicateKeywordArgument"),
                                   Ast.Constant(target.Name, typeof(string)),
                                   Ast.Constant(SymbolTable.IdToString(cf.KeywordArguments[0]), typeof(string))     // TODO: Report all bad arguments?
                                   )
                               ));

                case CallFailureReason.UnassignableKeyword:
                    return(ErrorInfo.FromException(
                               Ast.Call(
                                   typeof(BinderOps).GetMethod("TypeErrorForExtraKeywordArgument"),
                                   Ast.Constant(target.Name, typeof(string)),
                                   Ast.Constant(SymbolTable.IdToString(cf.KeywordArguments[0]), typeof(string))     // TODO: Report all bad arguments?
                                   )
                               ));

                default: throw new InvalidOperationException();
                }
            }
            throw new InvalidOperationException();
        }