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


C# Ast.MethodDeclaration类代码示例

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


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

示例1: HasReturnValue_HasNone

        public void HasReturnValue_HasNone()
        {
            var methodToTest = new MethodDeclaration();
            var victim = new TestableMethodTemplate(methodToTest, null);

            Assert.IsFalse(victim.HasReturnValue);
        }
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:7,代码来源:AbstractMethodTemplate.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: IsMethodInExternalTypes

        protected bool IsMethodInExternalTypes(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
        {
            bool found = false;
            foreach (TypeReference baseType in typeDeclaration.BaseTypes)
            {
                string fullName = GetFullName(baseType);
                if (!found && CodeBase.Types.Contains(fullName))
                {
                    TypeDeclaration baseTypeDeclaration = (TypeDeclaration) CodeBase.Types[fullName];

                    if (IsInExternalLibraries(fullName) || fullName.StartsWith("Helpers."))
                    {
                        IList methods = AstUtil.GetChildrenWithType(baseTypeDeclaration, typeof(MethodDeclaration));
                        if (ContainsMethod(methods, methodDeclaration))
                            found = true;
                        else
                            found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
                    }
                    else
                        found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
                    if (found)
                        break;
                }
            }
            return found;
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:26,代码来源:Refactoring.cs

示例4: VisitMethodDeclaration

        public override object VisitMethodDeclaration(MethodDeclaration declaration, object data)
        {
            if (!HasContainerType(declaration, ClassType.Interface) && declaration.InterfaceImplementations.Count == 0) 
                MakePublic(declaration);

            return base.VisitMethodDeclaration(declaration, data);
        }
开发者ID:bleissem,项目名称:SymbolSource.Community,代码行数:7,代码来源:Uninternalizer.cs

示例5: TrackedVisitTypeDeclaration

        public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            if (IsDerivedFrom(typeDeclaration, "Comparator"))
            {
                IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));

                MethodDeclaration equalsMethod = new MethodDeclaration("equals",
                                                                       Modifiers.Public, AstUtil.GetTypeReference("bool", typeDeclaration), new List<ParameterDeclarationExpression>(), null);
                equalsMethod.Parent = typeDeclaration;

                TypeReference argTypeReference = AstUtil.GetTypeReference("java.lang.Object", equalsMethod);
                argTypeReference.RankSpecifier = new int[] {};
                equalsMethod.Parameters.Add(new ParameterDeclarationExpression(argTypeReference, "obj"));

                if (Contains(methods, equalsMethod))
                {
                    int index = IndexOf(methods, equalsMethod);
                    MethodDeclaration method = (MethodDeclaration) methods[index];
                    AstUtil.RemoveModifierFrom(method, Modifiers.Abstract);
                    method.TypeReference.Type = "bool";
                    CreateMethodImplementation(method);
                }
                else
                {
                    CreateMethodImplementation(equalsMethod);
                    typeDeclaration.Children.Add(equalsMethod);
                    equalsMethod.Parent = typeDeclaration;
                }
            }
            return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:31,代码来源:IKVMDifferencesTransformer.cs

示例6: TrackedVisitTypeDeclaration

        public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            if (IsAbstractClass(typeDeclaration))
            {
                IList currentClassMethods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
                currentClassMethods = GetMethodsInParents(typeDeclaration, currentClassMethods, true);
                IList methodsInParents = new ArrayList();
                methodsInParents = GetMethodsInParents(typeDeclaration, methodsInParents, false);
                methodsInParents = FilterImplementedMethods(methodsInParents);
                IList abstractMethods = GetDiffList(currentClassMethods, methodsInParents);

                if (abstractMethods.Count > 0)
                {
                    TypeDeclaration replacedTypeDeclaration = typeDeclaration;
                    foreach (MethodDeclaration method in abstractMethods)
                    {
                        MethodDeclaration newMethod;
                        newMethod = new MethodDeclaration(method.Name,
                                                          Modifiers.Public | Modifiers.Abstract,
                                                          method.TypeReference,
                                                          method.Parameters,
                                                          method.Attributes);
                        newMethod.Parent = replacedTypeDeclaration;
                        replacedTypeDeclaration.Children.Add(newMethod);
                    }
                    ReplaceCurrentNode(replacedTypeDeclaration);
                }
            }
            return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:30,代码来源:AbstractClassTransformer.cs

示例7: VisitMethodDeclaration

            public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
            {
                if (methodDeclaration.Modifier.HasFlag(Modifiers.Abstract))
                    UnlockWith(methodDeclaration);

                return base.VisitMethodDeclaration(methodDeclaration, data);
            }
开发者ID:timdams,项目名称:strokes,代码行数:7,代码来源:AbstractMethod.cs

示例8: VisitMethodDeclaration

            public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
            {
                if (methodDeclaration.Name.ToLower().Equals("main") && !methodDeclaration.Modifier.HasFlag(Modifiers.Constructors))
                {
                    if (!methodDeclaration.IsExtensionMethod && !methodDeclaration.Modifier.HasFlag(Modifiers.Abstract))
                    {
                        if (methodDeclaration.Parameters.Count==1)
                        {
                            ParameterDeclarationExpression param = methodDeclaration.Parameters[0];

                            if(param.ParameterName.Equals("args") && param.TypeReference.ToString().Equals("System.String[]"))
                            {
                                //now check if body uses argsparam
                                //This is waaaaay to naive....
                                if(methodDeclaration.Body.ToString().Contains("args"))
                                {
                                    UnlockWith(methodDeclaration);
                                }

                            }
                        }
                    }
                }

                return base.VisitMethodDeclaration(methodDeclaration, data);
            }
开发者ID:timdams,项目名称:strokes,代码行数:26,代码来源:ProgramWithStartupParamsAchievement.cs

示例9: VerifyMethodCondition

        protected override bool VerifyMethodCondition(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
        {
            IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
            string name = methodDeclaration.Name.Substring(3);

            if (Contains(methods, methodDeclaration))
            {
                IList innerTypes = AstUtil.GetChildrenWithType(typeDeclaration, typeof(TypeDeclaration));
                foreach (TypeDeclaration innerType in innerTypes)
                {
                    if (innerType.Name == name)
                        return true;
                }
                IList constructors = AstUtil.GetChildrenWithType(typeDeclaration, typeof(ConstructorDeclaration));
                foreach (ConstructorDeclaration constructorDeclaration in constructors)
                {
                    if (constructorDeclaration.Name == name)
                        return true;
                }
                foreach (MethodDeclaration method in methods)
                {
                    if (method.Name == name || char.ToUpper(method.Name[0]) + method.Name.Substring(1) == name)
                        return true;
                }
            }
            else
            {
                IList properties = AstUtil.GetChildrenWithType(typeDeclaration, typeof(PropertyDeclaration));
                return Contains(properties, name);
            }
            return false;
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:32,代码来源:AccessorRefactoringHelper.cs

示例10: ConvertInterfaceImplementation

		void ConvertInterfaceImplementation(MethodDeclaration member)
		{
			// members without modifiers are already C# explicit interface implementations, do not convert them
			if (member.Modifier == Modifiers.None)
				return;
			while (member.InterfaceImplementations.Count > 0) {
				InterfaceImplementation impl = member.InterfaceImplementations[0];
				member.InterfaceImplementations.RemoveAt(0);
				if (member.Name != impl.MemberName) {
					MethodDeclaration newMember = new MethodDeclaration {
						Name = impl.MemberName,
						TypeReference = member.TypeReference,
						Parameters = member.Parameters,
						Body = new BlockStatement()
					};
					InvocationExpression callExpression = new InvocationExpression(new IdentifierExpression(member.Name));
					foreach (ParameterDeclarationExpression decl in member.Parameters) {
						callExpression.Arguments.Add(new IdentifierExpression(decl.ParameterName));
					}
					if (member.TypeReference.Type == "System.Void") {
						newMember.Body.AddChild(new ExpressionStatement(callExpression));
					} else {
						newMember.Body.AddChild(new ReturnStatement(callExpression));
					}
					newMember.InterfaceImplementations.Add(impl);
					InsertAfterSibling(member, newMember);
				}
			}
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:29,代码来源:ToCSharpConvertVisitor.cs

示例11: GenerateCode

		public override void GenerateCode(List<AbstractNode> nodes, IList items)
		{
			TypeReference stringReference = new TypeReference("System.String");
			MethodDeclaration method = new MethodDeclaration("ToString",
			                                                 Modifiers.Public | Modifiers.Override,
			                                                 stringReference,
			                                                 null, null);
			method.Body = new BlockStatement();
			Expression target = new FieldReferenceExpression(new TypeReferenceExpression(stringReference),
			                                                 "Format");
			InvocationExpression methodCall = new InvocationExpression(target);
			StringBuilder formatString = new StringBuilder();
			formatString.Append('[');
			formatString.Append(currentClass.Name);
			for (int i = 0; i < items.Count; i++) {
				formatString.Append(' ');
				formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name));
				formatString.Append("={");
				formatString.Append(i);
				formatString.Append('}');
			}
			formatString.Append(']');
			methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString()));
			foreach (FieldWrapper w in items) {
				methodCall.Arguments.Add(new FieldReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
			}
			method.Body.AddChild(new ReturnStatement(methodCall));
			nodes.Add(method);
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:29,代码来源:ToStringCodeGenerator.cs

示例12: VisitMethodDeclaration

		public override object VisitMethodDeclaration(MethodDeclaration md, object data)
		{
			Push();
			object result = base.VisitMethodDeclaration(md, data);
			Pop();
			return result;
		}
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:7,代码来源:PrefixFieldsVisitor.cs

示例13: Equals

        public bool Equals(MethodDeclaration firstMethod, MethodDeclaration secondMethod)
        {
            if (firstMethod.Name == secondMethod.Name)
            {
                if (firstMethod.Parameters.Count == secondMethod.Parameters.Count)
                {
                    int index = 0;
                    foreach (ParameterDeclarationExpression parameter in firstMethod.Parameters)
                    {
                        TypeReference parameterTypeReference = ((ParameterDeclarationExpression) secondMethod.Parameters[index]).TypeReference;
                        string firstMethodParam = parameter.TypeReference.Type;
                        if (firstMethodParam.IndexOf('.') != -1)
                            firstMethodParam = firstMethodParam.Substring(firstMethodParam.LastIndexOf('.') + 1);
                        string secondMethodParam = parameterTypeReference.Type;
                        if (secondMethodParam.IndexOf('.') != -1)
                            secondMethodParam = secondMethodParam.Substring(secondMethodParam.LastIndexOf('.') + 1);

                        if ((firstMethodParam == secondMethodParam || AreEqualTypes(parameter.TypeReference, parameterTypeReference)) &&
                            parameter.TypeReference.RankSpecifier.Length == parameterTypeReference.RankSpecifier.Length)
                            index++;
                        else
                            return false;
                    }
                    return true;
                }
            }
            return false;
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:28,代码来源:MethodRelatedTransformer.cs

示例14: TrackedVisitMethodDeclaration

 public override object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
 {
     TypeDeclaration typeDeclaration = (TypeDeclaration) methodDeclaration.Parent;
     if (methodDeclaration.Name.Length > 3)
     {
         if (IsAccessor(methodDeclaration, fields)
             || IsInterfaceOrAbstract(typeDeclaration) && ImplementInheritors(typeDeclaration, methodDeclaration)
             || ImplementSiblings(typeDeclaration, methodDeclaration))
         {
             string name = GetPropertyName(methodDeclaration);
             TypeReference typeReference = GetAccessorTypeReference(methodDeclaration);
             IList properties = AstUtil.GetChildrenWithType(typeDeclaration, typeof(PropertyDeclaration));
             PropertyDeclaration propertyDeclaration = GetProperty(properties, name, methodDeclaration.Modifier, typeReference);
             if (methodDeclaration.Name.StartsWith("set"))
                 AddSetSection(propertyDeclaration, methodDeclaration, fields);
             else if (methodDeclaration.Name.StartsWith("get"))
                 AddGetSection(propertyDeclaration, methodDeclaration, fields);
             AddToReferences(typeDeclaration, methodDeclaration.Name, propertyDeclaration.Name);
             if (!HasProperty(properties, name))
                 ReplaceCurrentNode(propertyDeclaration);
             else
                 RemoveCurrentNode();
         }
     }
     return base.TrackedVisitMethodDeclaration(methodDeclaration, data);
 }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:26,代码来源:AccessorRefactoring.cs

示例15: VisitMethodDeclaration

		public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
		{
			B.Method m = new B.Method(GetLexicalInfo(methodDeclaration));
			m.Name = methodDeclaration.Name;
			m.Modifiers = ConvertModifier(methodDeclaration, B.TypeMemberModifiers.Private);
			ConvertAttributes(methodDeclaration.Attributes, m.Attributes);
			if (currentType != null) currentType.Members.Add(m);
			if (methodDeclaration.HandlesClause.Count > 0) {
				// TODO: Convert handles clauses to [Handles] attribute
				AddError(methodDeclaration, "Handles-clause is not supported.");
			}
			m.ExplicitInfo = ConvertInterfaceImplementations(methodDeclaration.InterfaceImplementations, methodDeclaration, m);
			if (methodDeclaration.Templates.Count > 0) {
				AddError(methodDeclaration, "Declaring generic methods is not supported.");
			}
			ConvertParameters(methodDeclaration.Parameters, m.Parameters);
			m.EndSourceLocation = GetEndLocation((INode)methodDeclaration.Body ?? methodDeclaration);
			m.ReturnType = ConvertTypeReference(methodDeclaration.TypeReference);
			m.Body = ConvertMethodBlock(methodDeclaration.Body);
			if (m.Name == "Main" && m.IsStatic && m.Parameters.Count <= 1 &&
			    (methodDeclaration.TypeReference.Type == "System.Void" || methodDeclaration.TypeReference.Type == "System.Int32"))
			{
				entryPointMethod = m;
			}
			return m;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:26,代码来源:ConvertVisitorTypeMembers.cs


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