public static void Assign(this BlockStatement block, Expression left, Expression right) { if (left == null) throw new ArgumentNullException("left"); if (right == null) throw new ArgumentNullException("right"); AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right)); }
public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation) { this.Name = name; this.TypeRef = typeRef; this.StartPos = startPos; this.EndPos = endPos; this.IsConst = isConst; this.IsLoopVariable = isLoopVariable; this.Initializer = initializer; this.ParentLambdaExpression = parentLambdaExpression; this.IsQueryContinuation = isQueryContinuation; }
/// <summary> /// Returns the existing expression plus the specified integer value. /// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression /// (and thus its parent property is modified). /// </summary> public static Expression AddInteger(Expression expr, int value) { PrimitiveExpression pe = expr as PrimitiveExpression; if (pe != null && pe.Value is int) { int newVal = (int)pe.Value + value; return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); } BinaryOperatorExpression boe = expr as BinaryOperatorExpression; if (boe != null && boe.Op == BinaryOperatorType.Add) { // clone boe: boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); boe.Right = AddInteger(boe.Right, value); if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) { int newVal = (int)((PrimitiveExpression)boe.Right).Value; if (newVal == 0) { return boe.Left; } else if (newVal < 0) { ((PrimitiveExpression)boe.Right).Value = -newVal; boe.Op = BinaryOperatorType.Subtract; } } return boe; } if (boe != null && boe.Op == BinaryOperatorType.Subtract) { pe = boe.Right as PrimitiveExpression; if (pe != null && pe.Value is int) { int newVal = (int)pe.Value - value; if (newVal == 0) return boe.Left; // clone boe: boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); if (newVal < 0) { newVal = -newVal; boe.Op = BinaryOperatorType.Add; } boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); return boe; } } BinaryOperatorType opType = BinaryOperatorType.Add; if (value < 0) { value = -value; opType = BinaryOperatorType.Subtract; } return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); }
public CatchClause(Statement statementBlock) { StatementBlock = statementBlock; typeReference = TypeReference.Null; variableName = ""; condition = Expression.Null; }
public AddressOfExpression(Expression expression) { Expression = expression; }
void AddEventHandler(Expression eventExpr, Expression handler, object data) { methodReference = true; CodeExpression methodInvoker = (CodeExpression)handler.AcceptVisitor(this, data); methodReference = false; if (!(methodInvoker is CodeObjectCreateExpression)) { // we need to create an event handler here methodInvoker = new CodeObjectCreateExpression(new CodeTypeReference("System.EventHandler"), methodInvoker); } if (eventExpr is IdentifierExpression) { AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), ((IdentifierExpression)eventExpr).Identifier), methodInvoker)); } else { MemberReferenceExpression fr = (MemberReferenceExpression)eventExpr; AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression((CodeExpression)fr.TargetObject.AcceptVisitor(this, data), fr.MemberName), methodInvoker)); } }
public CaseLabel(BinaryOperatorType binaryOperatorType, Expression label) { BinaryOperatorType = binaryOperatorType; Label = label; toExpression = Expression.Null; }
public void AddVariable(TypeReference typeRef, string name, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation) { if (name == null || name.Length == 0) { return; } List<LocalLookupVariable> list; if (!variables.ContainsKey(name)) { variables[name] = list = new List<LocalLookupVariable>(); } else { list = (List<LocalLookupVariable>)variables[name]; } list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression, isQueryContinuation)); }
public TypeOfIsExpression(Expression expression, TypeReference typeReference) { Expression = expression; TypeReference = typeReference; }
public static Expression CheckNull(Expression expression) { return expression == null ? NullExpression.Instance : expression; }
public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) { Expression = expression; Op = op; }
public XmlAttributeExpression() { name = ""; literalValue = ""; expressionValue = Expression.Null; }
public CastExpression(TypeReference castTo) { CastTo = castTo; expression = Expression.Null; }
public WithStatement(Expression expression) { Expression = expression; body = BlockStatement.Null; }
public VariableDeclaration(string name, Expression initializer, TypeReference typeReference) { Name = name; Initializer = initializer; TypeReference = typeReference; fixedArrayInitialization = Expression.Null; }
public VariableDeclaration(string name) { Name = name; initializer = Expression.Null; typeReference = TypeReference.Null; fixedArrayInitialization = Expression.Null; }
public CollectionRangeVariable() { identifier = ""; expression = Expression.Null; type = TypeReference.Null; }
/// <summary> /// Just calls the BinaryOperatorExpression constructor, /// but being an extension method; this allows for a nicer /// infix syntax in some cases. /// </summary> public static BinaryOperatorExpression Operator(this Expression left, BinaryOperatorType op, Expression right) { return new BinaryOperatorExpression(left, op, right); }
public XmlElementExpression() { content = Expression.Null; nameExpression = Expression.Null; xmlName = ""; attributes = new List<XmlExpression>(); }
public UnaryOperatorExpression(UnaryOperatorType op) { Op = op; expression = Expression.Null; }
void CheckMemberReferenceExpression(Expression expr, string memberName, string targetObjectIdentifier) { Assert.IsTrue(expr is MemberReferenceExpression); Assert.IsTrue((expr as MemberReferenceExpression).MemberName == memberName && (expr as MemberReferenceExpression).TargetObject is IdentifierExpression && ((expr as MemberReferenceExpression).TargetObject as IdentifierExpression).Identifier == targetObjectIdentifier); }
public CastExpression(TypeReference castTo, Expression expression, CastType castType) { CastTo = castTo; Expression = expression; CastType = castType; }
public XmlEmbeddedExpression() { inlineVBExpression = Expression.Null; }
public XmlMemberAccessExpression(Expression targetObject, XmlAxisType axisType, string identifier, bool isXmlIdentifier) { TargetObject = targetObject; AxisType = axisType; Identifier = identifier; IsXmlIdentifier = isXmlIdentifier; }
public static void AddStatement(this BlockStatement block, Expression expressionStatement) { if (expressionStatement == null) throw new ArgumentNullException("expressionStatement"); AddStatement(block, new ExpressionStatement(expressionStatement)); }
public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock) { TypeReference = typeReference; VariableName = variableName; StatementBlock = statementBlock; condition = Expression.Null; }
public static void Throw(this BlockStatement block, Expression expression) { if (expression == null) throw new ArgumentNullException("expression"); AddStatement(block, new ThrowStatement(expression)); }
public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition) { TypeReference = typeReference; VariableName = variableName; StatementBlock = statementBlock; Condition = condition; }
Expression CheckPropertyInitializationExpression(Expression e, string name) { Assert.IsInstanceOf(typeof(MemberInitializerExpression), e); Assert.AreEqual(name, ((MemberInitializerExpression)e).Name); return ((MemberInitializerExpression)e).Expression; }
public CaseLabel(Expression label, Expression toExpression) { Label = label; ToExpression = toExpression; }