本文整理汇总了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;
}