Example #1
0
        /// <summary>
        /// 实例(转换成功会自动为变量赋值)。
        /// </summary>
        /// <param name="variable">变量。</param>
        public ICaseHandler Case(VariableAst variable)
        {
            if (variable is null)
            {
                throw new ArgumentNullException(nameof(variable));
            }

            IPrivateCaseHandler handler;

            switch (switchValueKind)
            {
            case MySwitchValueKind.RuntimeType:
                handler = new SwitchCaseRuntimeTypeAst(variable, RuntimeType);
                break;

            case MySwitchValueKind.Arithmetic:
            case MySwitchValueKind.Equality:
                throw new AstException("当前流程控制为值比较转换,请使用“{Case(ConstantAst constant)}”方法处理!");

            default:
                throw new NotSupportedException();
            }

            switchCases.Add(handler);

            return(handler);
        }
Example #2
0
 protected CatchAst(CatchAst catchAst) : base(catchAst?.RuntimeType)
 {
     if (catchAst is null)
     {
         throw new ArgumentNullException(nameof(catchAst));
     }
     variable      = catchAst.variable;
     exceptionType = catchAst.exceptionType;
 }
Example #3
0
        /// <summary>
        /// 捕获“<paramref name="variable"/>.RuntimeType”的异常,并将异常赋值给指定变量。
        /// </summary>
        /// <param name="returnType">返回类型。</param>
        /// <param name="variable">变量。</param>
        /// <returns></returns>
        public IErrorHandler Catch(Type returnType, VariableAst variable)
        {
            if (variable is null)
            {
                throw new ArgumentNullException(nameof(variable));
            }

            var catchAst = new CatchAst(returnType, variable);

            catchAsts.Add(catchAst);

            return(catchAst);
        }
Example #4
0
            public CatchAst(Type returnType, VariableAst variable) : base(returnType)
            {
                if (variable is null)
                {
                    throw new ArgumentNullException(nameof(variable));
                }

                this.exceptionType = variable.RuntimeType;

                if (exceptionType == typeof(Exception) || exceptionType.IsAssignableFrom(typeof(Exception)))
                {
                    this.variable = variable;
                }
                else
                {
                    throw new AstException($"变量类型“{exceptionType}”未继承“{typeof(Exception)}”异常基类!");
                }
            }
Example #5
0
 /// <summary>
 /// 捕获“<paramref name="variable"/>.RuntimeType”异常,并将异常赋值给指定变量。
 /// </summary>
 /// <returns></returns>
 public IErrorHandler Catch(VariableAst variable) => Catch(RuntimeType, variable);
Example #6
0
 public SwitchCaseRuntimeTypeAst(VariableAst variableAst, Type returnType) : base(returnType)
 {
     this.variableAst = variableAst;
 }