コード例 #1
0
		internal static IConstantValue ConvertConstantValue(
			ITypeReference targetType, AstNode expression,
			IUnresolvedTypeDefinition parentTypeDefinition, IUnresolvedMethod parentMethodDefinition, UsingScope parentUsingScope)
		{
			ConstantValueBuilder b = new ConstantValueBuilder(false);
			ConstantExpression c = expression.AcceptVisitor(b, null);
			if (c == null)
				return new ErrorConstantValue(targetType);
			PrimitiveConstantExpression pc = c as PrimitiveConstantExpression;
			if (pc != null && pc.Type == targetType) {
				// Save memory by directly using a SimpleConstantValue.
				return new SimpleConstantValue(targetType, pc.Value);
			}
			// cast to the desired type
			return new ConstantCast(targetType, c);
		}
コード例 #2
0
        IConstantValue ConvertConstantValue(ITypeReference targetType, AstNode expression)
        {
            ConstantValueBuilder b = new ConstantValueBuilder();

            b.convertVisitor = this;
            ConstantExpression c = expression.AcceptVisitor(b, null);

            if (c == null)
            {
                return(null);
            }
            PrimitiveConstantExpression pc = c as PrimitiveConstantExpression;

            if (pc != null && pc.Type == targetType)
            {
                // Save memory by directly using a SimpleConstantValue.
                return(new SimpleConstantValue(targetType, pc.Value));
            }
            // cast to the desired type
            return(new CSharpConstantValue(new ConstantCast(targetType, c), usingScope, currentTypeDefinition));
        }
コード例 #3
0
        IConstantValue ConvertAttributeArgument(Expression expression)
        {
            ConstantValueBuilder b = new ConstantValueBuilder();

            b.convertVisitor      = this;
            b.isAttributeArgument = true;
            ConstantExpression c = expression.AcceptVisitor(b, null);

            if (c == null)
            {
                return(null);
            }
            PrimitiveConstantExpression pc = c as PrimitiveConstantExpression;

            if (pc != null)
            {
                // Save memory by directly using a SimpleConstantValue.
                return(new SimpleConstantValue(pc.Type, pc.Value));
            }
            else
            {
                return(new CSharpConstantValue(c, usingScope, currentTypeDefinition));
            }
        }
コード例 #4
0
		IConstantValue ConvertAttributeArgument(Expression expression)
		{
			ConstantValueBuilder b = new ConstantValueBuilder(true);
			return expression.AcceptVisitor(b, null);
		}