当前位置: 首页>>代码示例>>C#>>正文


C# AST.Evaluate方法代码示例

本文整理汇总了C#中Microsoft.JScript.AST.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# AST.Evaluate方法的具体用法?C# AST.Evaluate怎么用?C# AST.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.JScript.AST的用法示例。


在下文中一共展示了AST.Evaluate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssignmentCompatible

 internal static bool AssignmentCompatible(IReflect lhir, AST rhexpr, IReflect rhir, bool reportError){
   if (rhexpr is ConstantWrapper){
     Object rhval = rhexpr.Evaluate();
     if (rhval is ClassScope){
       if (lhir == Typeob.Type || lhir == Typeob.Object || lhir == Typeob.String) return true;
       else{
         if (reportError) rhexpr.context.HandleError(JSError.TypeMismatch);
         return false;
       }
     }
     ClassScope csc = lhir as ClassScope;
     if (csc != null){
       EnumDeclaration ed = csc.owner as EnumDeclaration;
       if (ed != null){
         ConstantWrapper cw = rhexpr as ConstantWrapper;
         if (cw != null && cw.value is String){
           FieldInfo field = csc.GetField((String)cw.value, BindingFlags.Public|BindingFlags.Static);
           if (field == null) return false;
           ed.PartiallyEvaluate();
           cw.value = new EnumWrapper(((JSMemberField)field).value, field.Name, csc);
         }
         if (rhir == Typeob.String) return true;
         lhir = ed.baseType.ToType();
       }
     }
     if (lhir is Type){
       try{
         Convert.CoerceT(rhval, (Type)lhir);
         return true;
       }catch(Exception){
         if (lhir == Typeob.Single && rhval is Double){
           if (((ConstantWrapper)rhexpr).isNumericLiteral) return true;
           Double d = (Double)rhval;
           Single s = (Single)d;
           if (d.ToString().Equals(s.ToString())){
             ((ConstantWrapper)rhexpr).value = s;
             return true;
           }
         }
         if (lhir == Typeob.Decimal){
           ConstantWrapper cw = rhexpr as ConstantWrapper;
           if (cw != null && cw.isNumericLiteral){
             try{
               Convert.CoerceT(cw.context.GetCode(), Typeob.Decimal);
               return true;
             }catch(Exception){}
           }
         }
         if (reportError)
           rhexpr.context.HandleError(JSError.TypeMismatch);
       }
       return false;
     }
   }else if (rhexpr is ArrayLiteral)
     return ((ArrayLiteral)rhexpr).AssignmentCompatible(lhir, reportError);
   if (rhir == Typeob.Object) return true; //Too little is known about the expression to complain at compile time
   if (rhir == Typeob.Double && Convert.IsPrimitiveNumericType(lhir)) return true; //Arithmetic expressions infer to Double, but might have the right result.
   if (lhir is Type && typeof(Delegate).IsAssignableFrom((Type)lhir) && rhir == Typeob.ScriptFunction && 
       rhexpr is Binding && ((Binding)rhexpr).IsCompatibleWithDelegate((Type)lhir))
     return true;
   if (Convert.IsPromotableTo(rhir, lhir))
     return true; //rhexpr delivers a value that can be converted to something expected by the assignment target
   if (Convert.IsJScriptArray(rhir) && Binding.ArrayAssignmentCompatible(rhexpr, lhir))
     return true;
   if (lhir == Typeob.String) 
     return true;  // Everything is assignment-compatible to string.
   if (rhir == Typeob.String && (lhir == Typeob.Boolean || Convert.IsPrimitiveNumericType(lhir))){
     if (reportError) rhexpr.context.HandleError(JSError.PossibleBadConversionFromString);
     return true;
   }
   if ((lhir == Typeob.Char && rhir == Typeob.String) || Convert.IsPromotableTo(lhir, rhir) ||
       (Convert.IsPrimitiveNumericType(lhir) && Convert.IsPrimitiveNumericType(rhir))){
     if (reportError) rhexpr.context.HandleError(JSError.PossibleBadConversion);
     return true;
   }
   
   if (reportError)
     rhexpr.context.HandleError(JSError.TypeMismatch);
   return false;
 }
开发者ID:ArildF,项目名称:masters,代码行数:80,代码来源:binding.cs


注:本文中的Microsoft.JScript.AST.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。