Inheritance: IReflect
コード例 #1
0
 internal override AST PartiallyEvaluate()
 {
     if (this.alreadyPartiallyEvaluated)
     {
         return(this);
     }
     this.alreadyPartiallyEvaluated = true;
     if (this.inBrackets && this.AllParamsAreMissing())
     {
         if (this.isConstructor)
         {
             this.args.context.HandleError(JSError.TypeMismatch);
         }
         IReflect ir = ((TypeExpression)(new TypeExpression(this.func)).PartiallyEvaluate()).ToIReflect();
         return(new ConstantWrapper(new TypedArray(ir, this.args.count + 1), this.context));
     }
     this.func = this.func.PartiallyEvaluateAsCallable();
     this.args = (ASTList)this.args.PartiallyEvaluate();
     IReflect[] argIRs = this.ArgIRs();
     this.func.ResolveCall(this.args, argIRs, this.isConstructor, this.inBrackets);
     if (!this.isConstructor && !this.inBrackets && this.func is Binding && this.args.count == 1)
     {
         Binding b = (Binding)this.func;
         if (b.member is Type)
         {
             Type            t    = (Type)b.member;
             ConstantWrapper arg0 = this.args[0] as ConstantWrapper;
             if (arg0 != null)
             {
                 try{
                     if (arg0.value == null || arg0.value is DBNull)
                     {
                         return(this);
                     }
                     else if (arg0.isNumericLiteral && (t == Typeob.Decimal || t == Typeob.Int64 || t == Typeob.UInt64 || t == Typeob.Single))
                     {
                         return(new ConstantWrapper(Convert.CoerceT(arg0.context.GetCode(), t, true), this.context));
                     }
                     else
                     {
                         return(new ConstantWrapper(Convert.CoerceT(arg0.Evaluate(), t, true), this.context));
                     }
                 }catch {
                     arg0.context.HandleError(JSError.TypeMismatch);
                 }
             }
             else
             {
                 if (!Binding.AssignmentCompatible(t, this.args[0], argIRs[0], false))
                 {
                     this.args[0].context.HandleError(JSError.ImpossibleConversion);
                 }
             }
         }
         else if (b.member is JSVariableField)
         {
             JSVariableField field = (JSVariableField)b.member;
             if (field.IsLiteral)
             {
                 if (field.value is ClassScope)
                 {
                     ClassScope csc = (ClassScope)field.value;
                     IReflect   ut  = csc.GetUnderlyingTypeIfEnum();
                     if (ut != null)
                     {
                         if (!Convert.IsPromotableTo(argIRs[0], ut) && !Convert.IsPromotableTo(ut, argIRs[0]) && (argIRs[0] != Typeob.String || ut == csc))
                         {
                             this.args[0].context.HandleError(JSError.ImpossibleConversion);
                         }
                     }
                     else
                     {
                         if (!Convert.IsPromotableTo(argIRs[0], csc) && !Convert.IsPromotableTo(csc, argIRs[0]))
                         {
                             this.args[0].context.HandleError(JSError.ImpossibleConversion);
                         }
                     }
                 }
                 else if (field.value is TypedArray)
                 {
                     TypedArray ta = (TypedArray)field.value;
                     if (!Convert.IsPromotableTo(argIRs[0], ta) && !Convert.IsPromotableTo(ta, argIRs[0]))
                     {
                         this.args[0].context.HandleError(JSError.ImpossibleConversion);
                     }
                 }
             }
         }
     }
     return(this);
 }
コード例 #2
0
        internal Type ToType()
        {
            Type elemType = Convert.ToType(this.elementType);

            return(Convert.ToType(TypedArray.ToRankString(this.rank), elemType));
        }