Пример #1
0
 /// <summary>
 /// Initilized a new instance of <see cref="BindError"/>.
 /// </summary>
 /// <param name="type">The type of error.</param>
 /// <param name="parameter">Which <see cref="Parameter"/> does this relate to.</param>
 /// <param name="nodes">Which <see cref="AstNode"/> does this relate to.</param>
 /// <param name="message">Error message that will be shown to the end-user.</param>
 public BindError(ErrorType type, IEnumerable<Parameter> parameter, AstNode[] nodes, string message)
 {
     this.Type = type;
     this.Parameter = parameter.ToArray();
     this.Argument = nodes;
     this.Message = message;
 }
Пример #2
0
 public TypeError(Type targetType, object value, AstNode astNode, params Exception[] exceptions)
 {
     this.TargetType = targetType;
     this.Value = value;
     this.AstNode = astNode;
     this.Exceptions = exceptions;
 }
Пример #3
0
 public ActivationError(ConstructorInfo ctor, object[] parameters, AstNode[] astNodes, Exception exception)
 {
     this.Exception = exception;
     this.Constructor = ctor;
     this.Parameters = parameters;
     this.AstNodes = astNodes;
 }
Пример #4
0
 public AddError(MethodInfo method, object[] parameters, AstNode[] astNodes, Exception exception)
 {
     this.Exception = exception;
     this.Method = method;
     this.Parameters = parameters;
     this.AstNodes = astNodes;
 }
        public bool Build(Type propertyType, AstNode astNode, out object value)
        {
            if (this._errorHandlers.Count > 0)
                throw new InvalidOperationException("This method is not reentrant.");

            if (this._errorCollector != null)
                this._errorCollector.Dispose();

            this._errorCollector = new ErrorCollector(this);

            this._targetType.Push(propertyType);

            value = astNode.Visit(this);

            this._targetType.Pop();

            return this._errorCollector.Count == 0;
        }
Пример #6
0
 public TypeError(Type targetType, object value, AstNode astNode, IEnumerable<Exception> exceptions)
     : this(targetType, value, astNode, exceptions.ToArray())
 {
     
 }
Пример #7
0
        private static void SetPropertyValue(BuildContext ctx, Parameter parameter, AstNode astNode)
        {
            using (ValueBuilder builder = new ValueBuilder())
            {
                object value;
                if (builder.Build(parameter.Property.PropertyType, astNode, out value))
                {
                    parameter.Property.SetValue(ctx.Instance, value, null);
                }
                else
                {
                    foreach (ValueError valueError in builder.Errors)
                    {
                        TypeError typeError = valueError as TypeError;
                        if (typeError != null)
                        {
                            string message = string.Format(ErrorMessages.IncompatibleType,
                                                           ctx.Sequence.GetInputString(typeError.AstNode.SourceInfo),
                                                           parameter.Name);

                            ctx.Errors.Add(new BindError(ErrorType.IncompatibleType,
                                                         new[] { parameter },
                                                         new[] { astNode },
                                                         message));
                        }

                        AddError addError = valueError as AddError;

                        if (addError != null)
                        {
                            string message = string.Format(ErrorMessages.MethodInvocationFailed,
                                                           ctx.Sequence.GetInputString(addError.AstNodes.Select(ast => ast.SourceInfo)),
                                                           parameter.Name,
                                                           addError.Method.ReflectedType.Name,
                                                           addError.Method.Name,
                                                           addError.Exception.GetType().Name,
                                                           addError.Exception.Message);

                            ctx.Errors.Add(new BindError(ErrorType.IncompatibleType,
                                                         new[] { parameter },
                                                         new[] { astNode },
                                                         message));
                        }
                        else
                        {
                            ActivationError activationError = valueError as ActivationError;

                            if (activationError != null)
                            {
                                string message = string.Format(ErrorMessages.ObjectInitializationFailed,
                                                               ctx.Sequence.GetInputString(activationError.AstNodes.Select(ast => ast.SourceInfo)),
                                                               parameter.Name,
                                                               activationError.Constructor.ReflectedType.Name,
                                                               activationError.Exception.GetType().Name,
                                                               activationError.Exception.Message);

                                ctx.Errors.Add(new BindError(ErrorType.IncompatibleType,
                                                             new[] { parameter },
                                                             new[] { astNode },
                                                             message));
                            }
                        }
                    }
                }
            }
        }