本文整理汇总了C#中Microsoft.CSharp.RuntimeBinder.Semantics.EXPR.isCONSTANT方法的典型用法代码示例。如果您正苦于以下问题:C# EXPR.isCONSTANT方法的具体用法?C# EXPR.isCONSTANT怎么用?C# EXPR.isCONSTANT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.RuntimeBinder.Semantics.EXPR
的用法示例。
在下文中一共展示了EXPR.isCONSTANT方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetObject
/////////////////////////////////////////////////////////////////////////////////
private object GetObject(EXPR pExpr)
{
if (pExpr.isCAST())
{
return GetObject(pExpr.asCAST().GetArgument());
}
else if (pExpr.isTYPEOF())
{
return pExpr.asTYPEOF().SourceType.type.AssociatedSystemType;
}
else if (pExpr.isMETHODINFO())
{
return GetMethodInfoFromExpr(pExpr.asMETHODINFO());
}
else if (pExpr.isCONSTANT())
{
CONSTVAL val = pExpr.asCONSTANT().Val;
CType underlyingType = pExpr.type;
object objval;
if (pExpr.type.IsNullType())
{
return null;
}
if (pExpr.type.isEnumType())
{
underlyingType = underlyingType.getAggregate().GetUnderlyingType();
}
switch (underlyingType.AssociatedSystemType.GetTypeCode())
{
case TypeCode.Boolean:
objval = val.boolVal;
break;
case TypeCode.SByte:
objval = val.sbyteVal;
break;
case TypeCode.Byte:
objval = val.byteVal;
break;
case TypeCode.Int16:
objval = val.shortVal;
break;
case TypeCode.UInt16:
objval = val.ushortVal;
break;
case TypeCode.Int32:
objval = val.iVal;
break;
case TypeCode.UInt32:
objval = val.uiVal;
break;
case TypeCode.Int64:
objval = val.longVal;
break;
case TypeCode.UInt64:
objval = val.ulongVal;
break;
case TypeCode.Single:
objval = val.floatVal;
break;
case TypeCode.Double:
objval = val.doubleVal;
break;
case TypeCode.Decimal:
objval = val.decVal;
break;
case TypeCode.Char:
objval = val.cVal;
break;
case TypeCode.String:
objval = val.strVal;
break;
default:
objval = val.objectVal;
break;
}
if (pExpr.type.isEnumType())
{
objval = Enum.ToObject(pExpr.type.AssociatedSystemType, objval);
}
return objval;
}
else if (pExpr.isZEROINIT())
{
if (pExpr.asZEROINIT().OptionalArgument != null)
{
return GetObject(pExpr.asZEROINIT().OptionalArgument);
}
return System.Activator.CreateInstance(pExpr.type.AssociatedSystemType);
}
Debug.Assert(false, "Invalid EXPR in GetObject");
throw Error.InternalCompilerError();
}
示例2: GetExpression
/////////////////////////////////////////////////////////////////////////////////
private Expression GetExpression(EXPR pExpr)
{
if (pExpr.isWRAP())
{
return _DictionaryOfParameters[pExpr.asWRAP().GetOptionalExpression().asCALL()];
}
else if (pExpr.isCONSTANT())
{
Debug.Assert(pExpr.type.IsNullType());
return null;
}
else
{
// We can have a convert node or a call of a user defined conversion.
Debug.Assert(pExpr.isCALL());
EXPRCALL call = pExpr.asCALL();
PREDEFMETH pm = call.PredefinedMethod;
Debug.Assert(pm == PREDEFMETH.PM_EXPRESSION_CONVERT ||
pm == PREDEFMETH.PM_EXPRESSION_CONVERT_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_NEWARRAYINIT ||
pm == PREDEFMETH.PM_EXPRESSION_CALL ||
pm == PREDEFMETH.PM_EXPRESSION_PROPERTY ||
pm == PREDEFMETH.PM_EXPRESSION_FIELD ||
pm == PREDEFMETH.PM_EXPRESSION_ARRAYINDEX ||
pm == PREDEFMETH.PM_EXPRESSION_ARRAYINDEX2 ||
pm == PREDEFMETH.PM_EXPRESSION_CONSTANT_OBJECT_TYPE ||
pm == PREDEFMETH.PM_EXPRESSION_NEW ||
// Binary operators.
pm == PREDEFMETH.PM_EXPRESSION_ASSIGN ||
pm == PREDEFMETH.PM_EXPRESSION_ADD ||
pm == PREDEFMETH.PM_EXPRESSION_AND ||
pm == PREDEFMETH.PM_EXPRESSION_DIVIDE ||
pm == PREDEFMETH.PM_EXPRESSION_EQUAL ||
pm == PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR ||
pm == PREDEFMETH.PM_EXPRESSION_GREATERTHAN ||
pm == PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL ||
pm == PREDEFMETH.PM_EXPRESSION_LEFTSHIFT ||
pm == PREDEFMETH.PM_EXPRESSION_LESSTHAN ||
pm == PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL ||
pm == PREDEFMETH.PM_EXPRESSION_MODULO ||
pm == PREDEFMETH.PM_EXPRESSION_MULTIPLY ||
pm == PREDEFMETH.PM_EXPRESSION_NOTEQUAL ||
pm == PREDEFMETH.PM_EXPRESSION_OR ||
pm == PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT ||
pm == PREDEFMETH.PM_EXPRESSION_SUBTRACT ||
pm == PREDEFMETH.PM_EXPRESSION_ORELSE ||
pm == PREDEFMETH.PM_EXPRESSION_ANDALSO ||
pm == PREDEFMETH.PM_EXPRESSION_ADD_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_AND_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_DIVIDE_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_EQUAL_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_GREATERTHAN_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_LEFTSHIFT_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_LESSTHAN_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_MODULO_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_MULTIPLY_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_NOTEQUAL_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_OR_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_SUBTRACT_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_ORELSE_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_ANDALSO_USER_DEFINED ||
// Checked binary
pm == PREDEFMETH.PM_EXPRESSION_ADDCHECKED ||
pm == PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED ||
pm == PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED ||
pm == PREDEFMETH.PM_EXPRESSION_ADDCHECKED_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED_USER_DEFINED ||
// Unary operators.
pm == PREDEFMETH.PM_EXPRESSION_NOT ||
pm == PREDEFMETH.PM_EXPRESSION_NEGATE ||
pm == PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_NEGATE_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_UNARYPLUS_USER_DEFINED ||
// Checked unary
pm == PREDEFMETH.PM_EXPRESSION_NEGATECHECKED ||
pm == PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED ||
pm == PREDEFMETH.PM_EXPRESSION_NEGATECHECKED_USER_DEFINED ||
pm == PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED_USER_DEFINED
);
switch (pm)
{
case PREDEFMETH.PM_EXPRESSION_CALL:
return GenerateCall(call).Expression;
case PREDEFMETH.PM_EXPRESSION_CONVERT:
case PREDEFMETH.PM_EXPRESSION_CONVERT_USER_DEFINED:
case PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED:
case PREDEFMETH.PM_EXPRESSION_CONVERTCHECKED_USER_DEFINED:
//.........这里部分代码省略.........