예제 #1
0
        public override bool Equals(Expression other)
        {
            if (other.CodeNodeType != CodeNodeType.DynamicMemberReferenceExpression)
            {
                return(false);
            }

            DynamicMemberReferenceExpression otherExpression = other as DynamicMemberReferenceExpression;

            if (!this.Target.Equals(otherExpression.Target) || this.MemberName != otherExpression.MemberName ||
                this.IsMethodInvocation != otherExpression.IsMethodInvocation)
            {
                return(false);
            }

            if (!this.IsMethodInvocation)
            {
                return(true);
            }

            if (!this.InvocationArguments.Equals(otherExpression.InvocationArguments) || this.IsGenericMethod != otherExpression.IsGenericMethod)
            {
                return(false);
            }

            if (!this.IsGenericMethod)
            {
                return(true);
            }

            using (IEnumerator <TypeReference> thisEnumerator = this.GenericTypeArguments.GetEnumerator())
            {
                using (IEnumerator <TypeReference> otherEnumerator = otherExpression.GenericTypeArguments.GetEnumerator())
                {
                    while (true)
                    {
                        bool thisMoveNext  = thisEnumerator.MoveNext();
                        bool otherMoveNext = otherEnumerator.MoveNext();
                        if (thisMoveNext != otherMoveNext)
                        {
                            return(false);
                        }

                        if (!thisMoveNext)
                        {
                            return(true);
                        }

                        if (thisEnumerator.Current != otherEnumerator.Current)
                        {
                            return(false);
                        }
                    }
                }
            }
        }
예제 #2
0
 public override Expression CloneExpressionOnly()
 {
     V_0 = new DynamicMemberReferenceExpression(this.get_Target().CloneExpressionOnly(), this.get_MemberName(), this.get_ExpressionType(), null);
     if (this.get_IsMethodInvocation())
     {
         V_0.set_IsMethodInvocation(true);
         V_0.set_InvocationArguments(this.get_InvocationArguments().CloneExpressionsOnly());
         if (this.get_IsGenericMethod())
         {
             V_0.set_GenericTypeArguments(new List <TypeReference>(this.get_GenericTypeArguments()));
         }
     }
     return(V_0);
 }
예제 #3
0
        public override Expression CloneExpressionOnly()
        {
            DynamicMemberReferenceExpression result = new DynamicMemberReferenceExpression(Target.CloneExpressionOnly(), this.MemberName, this.ExpressionType, (IEnumerable <Instruction>)null);

            if (this.IsMethodInvocation)
            {
                result.IsMethodInvocation  = true;
                result.InvocationArguments = this.InvocationArguments.CloneExpressionsOnly();
                if (this.IsGenericMethod)
                {
                    result.GenericTypeArguments = new List <TypeReference>(this.GenericTypeArguments);
                }
            }
            return(result);
        }
예제 #4
0
        public override Expression Clone()
        {
            DynamicMemberReferenceExpression clone = new DynamicMemberReferenceExpression(this.Target.Clone(), this.MemberName, this.ExpressionType, this.instructions);

            if (this.IsMethodInvocation)
            {
                clone.IsMethodInvocation  = true;
                clone.InvocationArguments = this.InvocationArguments.Clone();
                if (this.IsGenericMethod)
                {
                    clone.GenericTypeArguments = new List <TypeReference>(this.GenericTypeArguments);
                }
            }
            return(clone);
        }
 public override Expression CloneExpressionOnly()
 {
     DynamicMemberReferenceExpression result = new DynamicMemberReferenceExpression(Target.CloneExpressionOnly(), this.MemberName, this.ExpressionType, (IEnumerable<Instruction>)null);
     if (this.IsMethodInvocation)
     {
         result.IsMethodInvocation = true;
         result.InvocationArguments = this.InvocationArguments.CloneExpressionsOnly();
         if (this.IsGenericMethod)
         {
             result.GenericTypeArguments = new List<TypeReference>(this.GenericTypeArguments);
         }
     }
     return result;
 }
 public override Expression Clone()
 {
     DynamicMemberReferenceExpression clone = new DynamicMemberReferenceExpression(this.Target.Clone(), this.MemberName, this.ExpressionType, this.instructions);
     if(this.IsMethodInvocation)
     {
         clone.IsMethodInvocation = true;
         clone.InvocationArguments = this.InvocationArguments.Clone();
         if(this.IsGenericMethod)
         {
             clone.GenericTypeArguments = new List<TypeReference>(this.GenericTypeArguments);
         }
     }
     return clone;
 }
        public override void VisitDynamicMemberReferenceExpression(DynamicMemberReferenceExpression node)
        {
            bool isComplexTarget = IsComplexTarget(node.Target);
            if (isComplexTarget)
            {
                WriteToken("(");
            }
            Visit(node.Target);
            if (isComplexTarget)
            {
                WriteToken(")");
            }


            if (node.MemberName != null)
            {
                WriteToken(".");
                Write(node.MemberName);
            }

            if (node.IsMethodInvocation)
            {
                if (node.IsGenericMethod)
                {
                    WriteToken(GenericLeftBracket);
                    for (int i = 0; i < node.GenericTypeArguments.Count; i++)
                    {
                        if (i != 0)
                        {
                            WriteToken(",");
                            WriteSpace();
                        }

                        WriteReferenceAndNamespaceIfInCollision(node.GenericTypeArguments[i]);
                    }
                    WriteToken(GenericRightBracket);
                }

                WriteToken("(");
                for (int i = 0; i < node.InvocationArguments.Count; i++)
                {
                    if (i != 0)
                    {
                        WriteToken(",");
                        WriteSpace();
                    }

                    Visit(node.InvocationArguments[i]);
                }
                WriteToken(")");
            }
        }
 public virtual void VisitDynamicMemberReferenceExpression(DynamicMemberReferenceExpression node)
 {
     Visit(node.Target);
     if (node.IsMethodInvocation)
     {
         Visit(node.InvocationArguments);
     }
 }
		private void ReplaceIfWith(IfStatement theIf, BlockStatement statementBlock)
		{
			if (!CanReplaceIf(statementBlock)) 
			{
				throw new Exception(InvalidIsEventString);
			}

            DynamicMemberReferenceExpression dynamicMethodInvocation = (statementBlock.Statements[1] as ExpressionStatement).Expression as
                DynamicMemberReferenceExpression;

			if (dynamicMethodInvocation == null) // the expression was an assignment
			{ 
				dynamicMethodInvocation = ((statementBlock.Statements[1] as ExpressionStatement).Expression as BinaryExpression).Right as DynamicMemberReferenceExpression;
			}

            if (dynamicMethodInvocation.MemberName == null || !dynamicMethodInvocation.IsMethodInvocation ||
                dynamicMethodInvocation.IsGenericMethod || dynamicMethodInvocation.InvocationArguments.Count != 1)
            {
                throw new Exception(InvalidIsEventString);
            }

            int charIndex = dynamicMethodInvocation.MemberName.IndexOf('_');
            if (charIndex != 3 && charIndex != 6) //"add_" - 3, "remove_" - 6
            {
                throw new Exception(InvalidIsEventString);
            }

            DynamicMemberReferenceExpression dynamicMemberRef = new DynamicMemberReferenceExpression(dynamicMethodInvocation.Target,
                dynamicMethodInvocation.MemberName.Substring(charIndex + 1), dynamicMethodInvocation.ExpressionType, dynamicMethodInvocation.MappedInstructions);

            BinaryExpression theBinaryExpression = new BinaryExpression(charIndex == 3 ? BinaryOperator.AddAssign : BinaryOperator.SubtractAssign, dynamicMemberRef,
                dynamicMethodInvocation.InvocationArguments[0], dynamicMemberRef.ExpressionType, typeSystem, null);

            BlockStatement parent = (BlockStatement)theIf.Parent;
            int ifIndex = parent.Statements.IndexOf(theIf);

            ExpressionStatement theAssignStatement = new ExpressionStatement(theBinaryExpression);
            theAssignStatement.Parent = parent;
            parent.Statements[ifIndex] = theAssignStatement;

            if (statementBlock.Statements.Count == 3)
            {
                parent.AddStatementAt(ifIndex + 1, statementBlock.Statements[2].Clone());
            }
		}
        private Expression GenerateInvokeMemeberExpression(CallSiteInfo callSiteInfo, IList<Expression> arguments, IEnumerable<Instruction> instructions)
		{
            if (arguments.Count < 1)
            {
                throw new Exception("Invalid number of arguments for invoke expression.");
            }

            Expression target;
            TypeReference typeRef;
            if (arguments[0].CodeNodeType == CodeNodeType.MethodInvocationExpression &&
                (arguments[0] as MethodInvocationExpression).IsTypeOfExpression(out typeRef))
            {
                target = new TypeReferenceExpression(typeRef, arguments[0].UnderlyingSameMethodInstructions);
            }
            else
            {
                target = arguments[0];
            }

			DynamicMemberReferenceExpression dynamicMemberReferenceExpression = new DynamicMemberReferenceExpression(target, callSiteInfo.MemberName, objectTypeRef, instructions,
                GetAllButFirst(arguments), callSiteInfo.GenericTypeArguments);
			return dynamicMemberReferenceExpression;
		}