当前位置: 首页>>代码示例>>C#>>正文


C# Ast.ParameterDeclarationExpression类代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.Ast.ParameterDeclarationExpression的典型用法代码示例。如果您正苦于以下问题:C# ParameterDeclarationExpression类的具体用法?C# ParameterDeclarationExpression怎么用?C# ParameterDeclarationExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParameterDeclarationExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了ParameterDeclarationExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: add_Method

        public static MethodDeclaration add_Method(this TypeDeclaration typeDeclaration, string methodName, Dictionary<string, object> invocationParameters, BlockStatement body)
        {
            var newMethod = new MethodDeclaration
            {
                Name = methodName,
                //Modifier = Modifiers.None | Modifiers.Public | Modifiers.Static,
                Modifier = Modifiers.None | Modifiers.Public,
                Body = body
            };
            newMethod.setReturnType();
            if (invocationParameters != null)

                foreach (var invocationParameter in invocationParameters)
                {
                    var parameterType = new TypeReference(
                        (invocationParameter.Value != null && invocationParameter.Key != "returnData")
                        ? invocationParameter.Value.typeFullName()
                        : "System.Object", true);
                    var parameter = new ParameterDeclarationExpression(parameterType, invocationParameter.Key);
                    newMethod.Parameters.Add(parameter);

                }
            typeDeclaration.AddChild(newMethod);
            return newMethod;
        }
开发者ID:pusp,项目名称:o2platform,代码行数:25,代码来源:MethodDeclaration_ExtensionMethods.cs

示例2: Equals

        public void Equals()
        {
            string program = TestUtil.TypeMemberParse("public string Sentence(string title , string text);");
            CompilationUnit cu = TestUtil.ParseProgram(program);

            NamespaceDeclaration ns = (NamespaceDeclaration) cu.Children[0];
            TypeDeclaration ty = (TypeDeclaration) ns.Children[0];
            MethodDeclaration pgMethod = (MethodDeclaration) ty.Children[0];
            ParameterDeclarationExpression p1 = new ParameterDeclarationExpression(new TypeReference("string"), "title");
            p1.TypeReference.RankSpecifier = new int[] {};
            ParameterDeclarationExpression p2 = new ParameterDeclarationExpression(new TypeReference("string"), "text");
            p2.TypeReference.RankSpecifier = new int[] {};
            List<ParameterDeclarationExpression> argList = new List<ParameterDeclarationExpression>();
            argList.Add(p1);
            argList.Add(p2);
            MethodDeclaration exMethod = new MethodDeclaration("Sentence",
                                                               Modifiers.Public,
                                                               new TypeReference("string"),
                                                               argList, null);

            Assert.IsTrue(Equals(exMethod, pgMethod));

            string program2 = TestUtil.TypeMemberParse("public string Sentence(string title , string[] text);");
            cu = TestUtil.ParseProgram(program2);

            ns = (NamespaceDeclaration) cu.Children[0];
            ty = (TypeDeclaration) ns.Children[0];
            pgMethod = (MethodDeclaration) ty.Children[0];
            Assert.IsFalse(Equals(exMethod, pgMethod));
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:30,代码来源:MethodRelatedTransformerTest.cs

示例3: VisitParameterDeclarationExpression

		public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
		{
			if (nameComparer.Equals(from, parameterDeclarationExpression.ParameterName)) {
				parameterDeclarationExpression.ParameterName = to;
			}
			return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data);
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:7,代码来源:RenameIdentifierVisitor.cs

示例4: AddParameter

 /// <summary>
 /// Adds a <see cref="ParameterDeclarationExpression"/> to <see cref="ParametrizedNode.Parameters"/> in a single
 /// call, for convenience.
 /// </summary>
 /// 
 /// <param name="node">
 /// The method or constructor to add the parameter to.
 /// </param>
 /// 
 /// <param name="parameterType">
 /// The <see cref="TypeReference"/> of the parameter to add.
 /// </param>
 /// 
 /// <param name="parameterName">
 /// The name of the parameter to add.
 /// </param>
 /// 
 /// <returns>
 /// The <see cref="ParameterDeclarationExpression"/> instance that was created and added to
 /// <paramref name="node"/>.
 /// </returns>
 public static ParameterDeclarationExpression AddParameter(this ParametrizedNode node,
     TypeReference parameterType, string parameterName)
 {
     var parameter = new ParameterDeclarationExpression(parameterType, parameterName);
     node.Parameters.Add(parameter);
     return parameter;
 }
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:28,代码来源:RefactoryExtensions.cs

示例5: VisitParameterDeclarationExpression

 public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
 {
     if (parameterDeclarationExpression.ParamModifier == ParameterModifiers.Out)
     {
         UnlockWith(parameterDeclarationExpression);
     }
     return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data);
 }
开发者ID:timdams,项目名称:strokes,代码行数:8,代码来源:OutParameterAchievement.cs

示例6: VisitParameterDeclarationExpression

 public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
 {
     if (RenameTable.ContainsKey(parameterDeclarationExpression.ParameterName))
     {
         parameterDeclarationExpression.ParameterName = RenameTable[parameterDeclarationExpression.ParameterName];
     }
     return null;
 }
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:8,代码来源:RenameLocalVariableRefactoring.cs

示例7: TrackedVisitInvocationExpression

        public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            if (invocationExpression.TargetObject is IdentifierExpression)
            {
                TypeDeclaration typeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
                IdentifierExpression methodIdentifier = (IdentifierExpression) invocationExpression.TargetObject;

                if (typeDeclaration.Parent is TypeDeclaration)
                {
                    List<ParameterDeclarationExpression> argList = new List<ParameterDeclarationExpression>();
                    int i = 0;
                    foreach (Expression argument in invocationExpression.Arguments)
                    {
                        TypeReference argumentType = GetExpressionType(argument);
                        if (argumentType != null)
                        {
                            string argType = argumentType.Type;

                            TypeReference typeReference = new TypeReference(argType);
                            ParameterDeclarationExpression parameterExpression = new ParameterDeclarationExpression(typeReference, "arg" + i);
                            parameterExpression.TypeReference.RankSpecifier = new int[0];
                            i++;
                            argList.Add(parameterExpression);
                        }
                    }
                    MethodDeclaration argMethod = new MethodDeclaration(methodIdentifier.Identifier, Modifiers.None, null, argList, null);

                    IList parentMethods = GetAccessibleMethods((TypeDeclaration) typeDeclaration.Parent);
                    if (Contains(parentMethods, argMethod))
                    {
                        int methodIndex = IndexOf(parentMethods, argMethod);
                        argMethod = (MethodDeclaration) parentMethods[methodIndex];
                        if (!AstUtil.ContainsModifier(argMethod, Modifiers.Static))
                        {
                            string parentTypeName = ((TypeDeclaration) typeDeclaration.Parent).Name;
                            AddInstanceField(typeDeclaration, parentTypeName);
                            AddProperConstructor(typeDeclaration, parentTypeName);

                            FieldReferenceExpression newReference = new FieldReferenceExpression(
                                new IdentifierExpression(parentTypeName),
                                ((IdentifierExpression) invocationExpression.TargetObject).Identifier);
                            InvocationExpression newInvication = new InvocationExpression(newReference, invocationExpression.Arguments);
                            newInvication.Parent = invocationExpression.Parent;

                            ReplaceCurrentNode(newInvication);
                        }
                    }
                }
            }
            return base.TrackedVisitInvocationExpression(invocationExpression, data);
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:51,代码来源:InnerClassTransformer.cs

示例8: Contains

        public void Contains()
        {
            string program = TestUtil.GetInput();

            CompilationUnit cu = TestUtil.ParseProgram(program);
            NamespaceDeclaration ns = (NamespaceDeclaration) cu.Children[0];
            TypeDeclaration ty = (TypeDeclaration) ns.Children[0];
            IList methods = AstUtil.GetChildrenWithType(ty, typeof(MethodDeclaration));
            ParameterDeclarationExpression pm = new ParameterDeclarationExpression(
                new TypeReference("int"), "from");
            pm.TypeReference.RankSpecifier = new int[] {};
            List<ParameterDeclarationExpression> al = new List<ParameterDeclarationExpression>();
            al.Add(pm);
            MethodDeclaration myMethod = new MethodDeclaration("Distance", Modifiers.Protected,
                                                               new TypeReference("int"),
                                                               al, null);
            Assert.IsTrue(Contains(methods, myMethod));
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:18,代码来源:MethodRelatedTransformerTest.cs

示例9: IndexOf

        public void IndexOf()
        {
            string program = TestUtil.GetInput();

            CompilationUnit cu = TestUtil.ParseProgram(program);
            NamespaceDeclaration ns = (NamespaceDeclaration) cu.Children[0];
            TypeDeclaration ty = (TypeDeclaration) ns.Children[0];
            IList methodDecList = AstUtil.GetChildrenWithType(ty, typeof(MethodDeclaration));

            ParameterDeclarationExpression p1 = new ParameterDeclarationExpression(new TypeReference("Circle"), "circle");
            p1.TypeReference.RankSpecifier = new int[] {};
            List<ParameterDeclarationExpression> md1Param = new List<ParameterDeclarationExpression>();
            md1Param.Add(p1);
            MethodDeclaration md1 = new MethodDeclaration("GetRadius", Modifiers.Private, new TypeReference("int"), md1Param, null);

            int md1Index = IndexOf(methodDecList, md1);
            Assert.AreEqual(1, md1Index);

            MethodDeclaration md2 = new MethodDeclaration("ToString", Modifiers.Protected, new TypeReference("string"), null, null);
            int md2Index = IndexOf(methodDecList, md2);
            Assert.AreEqual(-1, md2Index);
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:22,代码来源:MethodRelatedTransformerTest.cs

示例10: ParameterNameSafe_PositiveCase

 public void ParameterNameSafe_PositiveCase()
 {
     const string reserved_word = "this";
     ParameterDeclarationExpression p = new ParameterDeclarationExpression(new TypeReference("foo"), reserved_word);
     Assert.AreEqual("@this", p.ParameterNameSafe());
 }
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:6,代码来源:AstMatchHelperTests.cs

示例11: VisitParameterDeclarationExpression

 public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
 {
     if (this.CheckNode(parameterDeclarationExpression)) {
         return null;
     }
     return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data);
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:7,代码来源:MemberFindAstVisitor.cs

示例12: PerformChanges


//.........这里部分代码省略.........
			node.AcceptVisitor (transformer, null);
			if (!param.OneChangedVariable && node is Expression) {
				ResolveResult resolveResult = resolver.Resolve (new ExpressionResult ("(" + provider.OutputNode (options.Dom, node) + ")"), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column));
				if (resolveResult.ResolvedType != null)
					returnType = options.ShortenTypeName (resolveResult.ResolvedType).ConvertToTypeReference ();
			}
			
			MethodDeclaration methodDecl = new MethodDeclaration ();
			methodDecl.Name = param.Name;
			methodDecl.Modifier = param.Modifiers;
			methodDecl.TypeReference = returnType;
			
			if (!param.ReferencesMember)
				methodDecl.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
			if (node is BlockStatement) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new EmptyStatement ());
				if (param.OneChangedVariable)
					methodDecl.Body.AddChild (new ReturnStatement (new IdentifierExpression (param.ChangedVariables.First ())));
			} else if (node is Expression) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new ReturnStatement (node as Expression));
			}
			
			foreach (VariableDescriptor var in param.VariablesToDefine) {
				BlockStatement block = methodDecl.Body;
				LocalVariableDeclaration varDecl = new LocalVariableDeclaration (options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ());
				varDecl.Variables.Add (new VariableDeclaration (var.Name));
				block.Children.Insert (0, varDecl);
			}
			
			foreach (VariableDescriptor var in param.Parameters) {
				TypeReference typeReference = options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ();
				ParameterDeclarationExpression pde = new ParameterDeclarationExpression (typeReference, var.Name);
				if (!param.OneChangedVariable) {
					if (param.ChangedVariables.Contains (var.Name))
						pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Ref;
					if (param.VariablesToGenerate.Where (v => v.Name == var.Name).Any ()) {
						pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Out;
					}
					VariableDescriptor outsideVar = null;
					if (var.GetsAssigned && param.VariablesOutside.TryGetValue (var.Name, out outsideVar)) {
						if (!outsideVar.GetsAssigned)
							pde.ParamModifier = ICSharpCode.NRefactory.Ast.ParameterModifiers.Out;
					}
				}
				
				methodDecl.Parameters.Add (pde);
			}
			
			string indent = options.GetIndent (param.DeclaringMember);
			StringBuilder methodText = new StringBuilder ();
			switch (param.InsertionPoint.LineBefore) {
			case NewLineInsertion.Eol:
				methodText.AppendLine ();
				break;
			case NewLineInsertion.BlankLine:
				methodText.Append (indent);
				methodText.AppendLine ();
				break;
			}
			if (param.GenerateComment) {
				methodText.Append (indent);
				methodText.AppendLine ("/// <summary>");
				methodText.Append (indent);
				methodText.AppendLine ("/// TODO: write a comment.");
开发者ID:pgoron,项目名称:monodevelop,代码行数:67,代码来源:ExtractMethodRefactoring.cs

示例13: Extract

		public override bool Extract()
		{
			using (var parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader("class Tmp { void Test() {\n " + this.textEditor.SelectedText + "\n}}"))) {
				parser.Parse();
				
				if (parser.Errors.Count > 0) {
					MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.ParseErrors}");
					
					return false;
				}
				
				this.specialsList = parser.Lexer.SpecialTracker.RetrieveSpecials();
			}
			
			this.currentProjectContent = ParserService.GetProjectContent(ProjectService.CurrentProject);
			
			MethodDeclaration newMethod = new MethodDeclaration();
			List<VariableDeclaration> possibleReturnValues = new List<VariableDeclaration>();
			List<VariableDeclaration> otherReturnValues = new List<VariableDeclaration>();
			
			// Initialise new method
			newMethod.Body = GetBlock(this.textEditor.SelectedText);
			newMethod.Body.StartLocation = new Location(0,0);
			
			this.parentNode = GetParentMember(start, end);
			
			Dom.IMember member = GetParentMember(textEditor, textEditor.Caret.Line, textEditor.Caret.Column);
			
			if (parentNode == null || member == null) {
				MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.InvalidSelection}");
				return false;
			}
			
			this.currentClass = member.DeclaringType;
			
			ErrorKind kind = CheckForJumpInstructions(newMethod);
			if (kind != ErrorKind.None) {
				switch (kind) {
					case ErrorKind.ContainsBreak:
						MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.ContainsBreakError}");
						break;
					case ErrorKind.ContainsContinue:
						MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.ContainsContinueError}");
						break;
					case ErrorKind.ContainsGoto:
						MessageService.ShowError("${res:AddIns.SharpRefactoring.ExtractMethod.ContainsGotoError}");
						break;
				}
				return false;
			}
			
			newMethod.Modifier = parentNode.Modifier;
			
			newMethod.Modifier &= ~(Modifiers.Internal | Modifiers.Protected | Modifiers.Private | Modifiers.Public | Modifiers.Override);
			
			LookupTableVisitor ltv = new LookupTableVisitor(SupportedLanguage.CSharp);
			
			parentNode.AcceptVisitor(ltv, null);
			
			var variablesList = (from list in ltv.Variables.Values from item in list select new Variable(item))
				.Where(v => !(v.StartPos > end || v.EndPos < start) &&
				       (HasReferencesInSelection(newMethod, v) || 
				        HasOccurrencesAfter(CSharpNameComparer, this.parentNode, end, v.Name, v.StartPos, v.EndPos)))
				.Union(FromParameters(newMethod))
				.Select(va => ResolveVariable(va));
			
			foreach (var variable in variablesList) {
				LoggingService.Debug(variable);
				
				bool hasOccurrencesAfter = HasOccurrencesAfter(CSharpNameComparer, this.parentNode, end, variable.Name, variable.StartPos, variable.EndPos);
				bool isInitialized = (variable.Initializer != null) ? !variable.Initializer.IsNull : false;
				bool hasAssignment = HasAssignment(newMethod, variable);
				
				if (IsInCurrentSelection(variable.StartPos) && hasOccurrencesAfter) {
					possibleReturnValues.Add(new VariableDeclaration(variable.Name, variable.Initializer, variable.Type));
					otherReturnValues.Add(new VariableDeclaration(variable.Name, variable.Initializer, variable.Type));
				}
				
				if (!(IsInCurrentSelection(variable.StartPos) || IsInCurrentSelection(variable.EndPos))) {
					ParameterDeclarationExpression newParam = null;

					if ((hasOccurrencesAfter && isInitialized) || variable.WasRefParam)
						newParam = new ParameterDeclarationExpression(variable.Type, variable.Name, ParameterModifiers.Ref);
					else {
						if ((hasOccurrencesAfter && hasAssignment) || variable.WasOutParam)
							newParam = new ParameterDeclarationExpression(variable.Type, variable.Name, ParameterModifiers.Out);
						else {
							if (!hasOccurrencesAfter)
								newParam = new ParameterDeclarationExpression(variable.Type, variable.Name, ParameterModifiers.None);
							else {
								if (!hasOccurrencesAfter && !isInitialized)
									newMethod.Body.Children.Insert(0, new LocalVariableDeclaration(new VariableDeclaration(variable.Name, variable.Initializer, variable.Type)));
								else
									newParam = new ParameterDeclarationExpression(variable.Type, variable.Name, ParameterModifiers.In);
							}
						}
					}
					if (newParam != null)
						newMethod.Parameters.Add(newParam);
				}
//.........这里部分代码省略.........
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:101,代码来源:CSharpMethodExtractor.cs

示例14: TrackedVisitParameterDeclarationExpression

 public override object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data)
 {
     Console.WriteLine("VisitParameterDeclarationExpression");
     return null;
 }
开发者ID:L3tum,项目名称:BesiegeScriptingMod,代码行数:5,代码来源:NRefactoryToPythonConverter.cs

示例15: TrackedVisitParameterDeclarationExpression

		public virtual object TrackedVisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) {
			return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data);
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:3,代码来源:NodeTrackingAstVisitor.cs


注:本文中的ICSharpCode.NRefactory.Ast.ParameterDeclarationExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。