Exemplo n.º 1
0
            public void Initialize(CloneContext previousCloneContext)
            {
                // Clone original context
                var cloneContext = new CloneContext();

                foreach (var keyValurPair in previousCloneContext)
                {
                    cloneContext.Add(keyValurPair.Key, keyValurPair.Value);
                }

                // Removes the method to clone
                cloneContext.Remove(Method);

                // Clone the old method with the clone context
                NewMethod = Method.DeepClone(cloneContext);

                var oldParameters = NewMethod.Parameters;

                NewMethod.Parameters = new List <Parameter>();
                int j = 0;

                for (int i = 0; i < oldParameters.Count; i++)
                {
                    var parameter     = oldParameters[i];
                    var variableValue = (Variable)this.Method.Parameters[i].GetTag(ScopeValueKey);
                    if (variableValue != null)
                    {
                        this.NewMethod.Body.Insert(j, new DeclarationStatement(parameter));
                        j++;
                        parameter.InitialValue = new VariableReferenceExpression(variableValue.Name)
                        {
                            TypeInference = { Declaration = variableValue, TargetType = variableValue.Type }
                        };
                    }
                    else
                    {
                        NewMethod.Parameters.Add(parameter);
                    }
                }

                // Create new method with new method name
                var methodNameBuild = new StringBuilder();

                methodNameBuild.Append(Method.Name);
                foreach (var variable in Variables)
                {
                    methodNameBuild.Append("_");
                    methodNameBuild.Append(variable.Name);
                }
                methodName     = methodNameBuild.ToString();
                NewMethod.Name = methodName;
            }
Exemplo n.º 2
0
            public void Initialize(CloneContext previousCloneContext)
            {
                // Clone original context
                var cloneContext = new CloneContext();

                foreach (var keyValurPair in previousCloneContext)
                {
                    cloneContext.Add(keyValurPair.Key, keyValurPair.Value);
                }

                // Removes the method to clone
                cloneContext.Remove(Method);

                // Clone the old method with the clone context
                NewMethod = Method.DeepClone(cloneContext);

                var oldParameters = NewMethod.Parameters;
                NewMethod.Parameters = new List<Parameter>();
                int j = 0;
                for (int i = 0; i < oldParameters.Count; i++)
                {
                    var parameter = oldParameters[i];
                    var variableValue = (Variable)this.Method.Parameters[i].GetTag(ScopeValueKey);
                    if (variableValue != null)
                    {
                        this.NewMethod.Body.Insert(j, new DeclarationStatement(parameter));
                        j++;
                        parameter.InitialValue = new VariableReferenceExpression(variableValue.Name) { TypeInference = { Declaration = variableValue, TargetType = variableValue.Type } };
                    }
                    else
                        NewMethod.Parameters.Add(parameter);
                }

                // Create new method with new method name
                var methodNameBuild = new StringBuilder();
                methodNameBuild.Append(Method.Name);
                foreach (var variable in Variables)
                {
                    methodNameBuild.Append("_");
                    methodNameBuild.Append(variable.Name);
                }
                methodName = methodNameBuild.ToString();
                NewMethod.Name = methodName;
            }