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


C# SeparatedSyntaxList.Add方法代码示例

本文整理汇总了C#中SeparatedSyntaxList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SeparatedSyntaxList.Add方法的具体用法?C# SeparatedSyntaxList.Add怎么用?C# SeparatedSyntaxList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SeparatedSyntaxList的用法示例。


在下文中一共展示了SeparatedSyntaxList.Add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitClassDeclaration

        public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            node = (ClassDeclarationSyntax)base.VisitClassDeclaration(node);
            SyntaxList<MemberDeclarationSyntax> newMembers = new SyntaxList<MemberDeclarationSyntax>();
            foreach (MemberDeclarationSyntax member in node.Members)
            {
                if (member.Kind == SyntaxKind.PropertyDeclaration)
                {
                    PropertyDeclarationSyntax prop = (PropertyDeclarationSyntax)member;
                    SyntaxList<AccessorDeclarationSyntax> newAccessors = new SyntaxList<AccessorDeclarationSyntax>();
                    bool implementfield = false;
                    foreach (AccessorDeclarationSyntax accessor in prop.AccessorList.Accessors)
                    {
                        if (accessor.Body == null)
                        {
                            switch (accessor.Kind)
                            {
                                case SyntaxKind.GetAccessorDeclaration:
                                    implementfield = true;
                                    newAccessors = newAccessors.Add(accessor.WithBody(Syntax.Block(Syntax.ReturnStatement(Syntax.IdentifierName("_" + prop.Identifier.ValueText)))));
                                    break;
                                case SyntaxKind.SetAccessorDeclaration:
                                    implementfield = true;
                                    newAccessors = newAccessors.Add(accessor.WithBody(Syntax.Block(Syntax.ExpressionStatement(Syntax.BinaryExpression(SyntaxKind.AssignExpression, Syntax.IdentifierName("_" + prop.Identifier.ValueText), Syntax.IdentifierName("value"))))));
                                    break;
                                default:
                                    newAccessors = newAccessors.Add(accessor);
                                    break;
                            }
                        }
                        else
                        {
                            newAccessors = newAccessors.Add(accessor);
                        }
                    }
                    if (implementfield)
                    {
                        SeparatedSyntaxList<VariableDeclaratorSyntax> variables = new SeparatedSyntaxList<VariableDeclaratorSyntax>();
                        variables = variables.Add(Syntax.VariableDeclarator("_" + prop.Identifier.ValueText));
                        newMembers = newMembers.Add(Syntax.FieldDeclaration(Syntax.VariableDeclaration(prop.Type, variables)));
                    }

                    newMembers = newMembers.Add(prop.WithAccessorList(prop.AccessorList.WithAccessors(newAccessors)));
                }
                else
                {
                    newMembers = newMembers.Add(member);
                }
            }
            return node.WithMembers(newMembers);
        }
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:51,代码来源:AutoImplementedPropertyRewriter.cs

示例2: RegisterCodeFixesAsync

        // TODO : not sure if this makes sense
        // Test and enable or add comment with reason
        //public override FixAllProvider GetFixAllProvider()
        //{
        //	return WellKnownFixAllProviders.BatchFixer;
        //}

        public async override Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var document = context.Document;
            var cancellationToken = context.CancellationToken;
            var span = context.Span;
            var diagnostics = context.Diagnostics;
            var root = await document.GetSyntaxRootAsync(cancellationToken);
            var diagnostic = diagnostics.First();
            var node = root.FindNode(context.Span) as InvocationExpressionSyntax;
            if (node == null)
                return;

            context.RegisterCodeFix(CodeActionFactory.Create(node.Span, diagnostic.Severity, "Change invocation to call 'object.ReferenceEquals'", arg =>
            {
                var arguments = new SeparatedSyntaxList<ArgumentSyntax>();
                arguments = arguments.Add(SyntaxFactory.Argument(SyntaxFactory.ThisExpression()));
                arguments = arguments.Add(node.ArgumentList.Arguments[0]);

                return Task.FromResult(document.WithSyntaxRoot(
                    root.ReplaceNode((SyntaxNode)
                        node,
                        SyntaxFactory.InvocationExpression(
                            SyntaxFactory.ParseExpression("object.ReferenceEquals"),
                            SyntaxFactory.ArgumentList(arguments)
                        )
                            .WithLeadingTrivia(node.GetLeadingTrivia())
                            .WithAdditionalAnnotations(Formatter.Annotation))
                    )
                );
            }), diagnostic);

            context.RegisterCodeFix(CodeActionFactory.Create(node.Span, diagnostic.Severity, "Remove 'base.'", arg =>
            {
                return Task.FromResult(document.WithSyntaxRoot(root.ReplaceNode((SyntaxNode)node, node.WithExpression(SyntaxFactory.IdentifierName("Equals")))));
            }), diagnostic);
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:43,代码来源:CallToObjectEqualsViaBaseCodeFixProvider.cs

示例3: VisitElementAccessExpression

        public override SyntaxNode VisitElementAccessExpression(ElementAccessExpressionSyntax node)
        {
            var elements = GetListCollectionInitializerElements(node);
            if (elements != null)
            {
                if (elements.Count > 0)
                {
                    var type = GetArgumentType(elements[0]);
                    var syntaxList = new SeparatedSyntaxList<ExpressionSyntax>();
                    var intializerExpr = Syntax.InitializerExpression(SyntaxKind.CollectionInitializerExpression, syntaxList.Add(elements.ToArray()));

                    return Syntax.ParseExpression(string.Format("new System.Collections.Generic.List<{1}>{0}", intializerExpr, type));
                }
                else
                {
                    //no elements of list - returning empty list of objects
                    return Syntax.ParseExpression("new System.Collections.Generic.List<Object>()");
                }

            }
            return base.VisitElementAccessExpression(node);
        }
开发者ID:ntr,项目名称:RoslynCSharpExtensions,代码行数:22,代码来源:ListsInitializerRewriter.cs

示例4: BuildHasFlagExpression

        static ExpressionSyntax BuildHasFlagExpression(ExpressionSyntax target, ExpressionSyntax expr)
        {
            var bOp = expr as BinaryExpressionSyntax;
            if (bOp != null)
            {
                if (bOp.IsKind(SyntaxKind.BitwiseOrExpression))
                {
                    return SyntaxFactory.BinaryExpression(
                        SyntaxKind.BitwiseOrExpression,
                        BuildHasFlagExpression(target, bOp.Left),
                        BuildHasFlagExpression(target, bOp.Right)
                    );
                }
            }

            var arguments = new SeparatedSyntaxList<ArgumentSyntax>();
            arguments = arguments.Add(SyntaxFactory.Argument(MakeFlatExpression(expr, SyntaxKind.BitwiseOrExpression)));

            return SyntaxFactory.InvocationExpression(
                SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, target, SyntaxFactory.IdentifierName("HasFlag")),
                SyntaxFactory.ArgumentList(arguments)
            );
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:23,代码来源:ConvertBitwiseFlagComparisonToHasFlagsCodeRefactoringProvider.cs

示例5: SimplifyMethodAndConstructorInvocation

            private static SyntaxNode SimplifyMethodAndConstructorInvocation(ref int numbering, ref SyntaxList<StatementSyntax> preList, SyntaxNode original, SyntaxNode origWithReplacedDesc)
            {
                SeparatedSyntaxList<ArgumentSyntax> slst = new SeparatedSyntaxList<ArgumentSyntax>();
                SeparatedSyntaxList<ArgumentSyntax> myArgs;
                InvocationExpressionSyntax ies = null;
                ObjectCreationExpressionSyntax oces = null;
                // es necesario manejarlos por separado, porque pese a que ambos tienen como propiedad Arguments
                // de tipo SeparatedSyntaxList<ArgumentSyntax>, no estan en la misma linea de jerarquia
                // de clases... entonces:
                if (origWithReplacedDesc.IsKind(SyntaxKind.InvocationExpression))
                {
                    ies = (InvocationExpressionSyntax)origWithReplacedDesc;
                    myArgs = ies.ArgumentList.Arguments;
                }
                else
                {
                    oces = (ObjectCreationExpressionSyntax)origWithReplacedDesc;
                    myArgs = oces.ArgumentList.Arguments;
                }
                foreach (var arg in myArgs)
                {
                    if (!(arg.Expression is LiteralExpressionSyntax || arg.Expression is IdentifierNameSyntax))
                    {
                        numbering++;
                        preList = preList.Add(SyntaxFactory.ParseStatement("var __a" + numbering + " = " + arg + ";"));
                        slst = slst.Add((SyntaxFactory.Argument(SyntaxFactory.ParseExpression("__a" + numbering))));
                    }
                }

                if (slst.Count() > 0)
                {
                    var argumentList = SyntaxFactory.ArgumentList(slst);
                    if (origWithReplacedDesc.IsKind(SyntaxKind.InvocationExpression))
                    {
                        return ies.WithArgumentList(argumentList);
                    }
                    else
                    {
                        return oces.WithArgumentList(argumentList);
                    }
                }
                else return original;
            }
开发者ID:TubaKayaDev,项目名称:Call-Graph-Builder-DotNet,代码行数:43,代码来源:MethodSimpifier.cs

示例6: CreateEmptyRule

            internal static FieldDeclarationSyntax CreateEmptyRule(SyntaxGenerator generator, string idName="Change me to the name of the above constant", string titleDefault="Enter a title for this diagnostic", string messageDefault="Enter a message to be displayed with this diagnostic",
                                                                    string categoryDefault="Enter a category for this diagnostic (e.g. Formatting)", ExpressionSyntax severityDefault=null, ExpressionSyntax enabledDefault=null)
            {
                if (severityDefault == null)
                {
                    severityDefault = generator.DefaultExpression(SyntaxFactory.ParseTypeName("DiagnosticSeverity")) as ExpressionSyntax;
                }

                if (enabledDefault == null)
                {
                    enabledDefault = generator.DefaultExpression(generator.TypeExpression(SpecialType.System_Boolean)) as ExpressionSyntax;
                }

                var type = SyntaxFactory.ParseTypeName("DiagnosticDescriptor");

                var arguments = new ArgumentSyntax[6];
                var whitespace = "            ";

                var id = generator.LiteralExpression(idName);
                var idArg = generator.Argument("id", RefKind.None, id).WithLeadingTrivia(SyntaxFactory.CarriageReturnLineFeed, SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
                arguments[0] = idArg;

                var title = generator.LiteralExpression(titleDefault);
                var titleArg = generator.Argument("title", RefKind.None, title).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
                arguments[1] = titleArg;

                var message = generator.LiteralExpression(messageDefault);
                var messageArg = generator.Argument("messageFormat", RefKind.None, message).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
                arguments[2] = messageArg;

                var category = generator.LiteralExpression(categoryDefault);
                var categoryArg = generator.Argument("category", RefKind.None, category).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
                arguments[3] = categoryArg;

                var defaultSeverityArg = generator.Argument("defaultSeverity", RefKind.None, severityDefault).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
                arguments[4] = defaultSeverityArg;

                var enabledArg = generator.Argument("isEnabledByDefault", RefKind.None, enabledDefault).WithLeadingTrivia(SyntaxFactory.Whitespace(whitespace)) as ArgumentSyntax;
                arguments[5] = enabledArg;
                
                var identifier = SyntaxFactory.ParseToken("spacingRule");

                var separators = new List<SyntaxToken>();
                var separator = SyntaxFactory.ParseToken(",").WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed);
                separators.Add(separator);
                separators.Add(separator);
                separators.Add(separator);
                separators.Add(separator);
                separators.Add(separator);

                var argumentsNewLines = SyntaxFactory.SeparatedList(arguments, separators);
                var argumentList = SyntaxFactory.ArgumentList(argumentsNewLines);
                var value = SyntaxFactory.ObjectCreationExpression(type, argumentList, null);
                var initializer = SyntaxFactory.EqualsValueClause(value);
                

                var variables = new SeparatedSyntaxList<VariableDeclaratorSyntax>();
                var variable = SyntaxFactory.VariableDeclarator(identifier, null, initializer);
                variables = variables.Add(variable);

                var declaration = SyntaxFactory.VariableDeclaration(type.WithTrailingTrivia(SyntaxFactory.Whitespace(" ")), variables);
                var modifiers = SyntaxFactory.TokenList(SyntaxFactory.ParseToken("internal").WithTrailingTrivia(SyntaxFactory.Whitespace(" ")), SyntaxFactory.ParseToken("static").WithTrailingTrivia(SyntaxFactory.Whitespace(" ")));
                var rule = SyntaxFactory.FieldDeclaration(new SyntaxList<AttributeListSyntax>(), modifiers, declaration);
                return rule;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:65,代码来源:CodeFixProvider.cs

示例7: DoTestAddInsertRemoveOnEmptyList

        private void DoTestAddInsertRemoveOnEmptyList(SeparatedSyntaxList<SyntaxNode> list)
        {
            Assert.Equal(0, list.Count);

            SyntaxNode nodeD = SyntaxFactory.ParseExpression("D");
            SyntaxNode nodeE = SyntaxFactory.ParseExpression("E");

            var newList = list.Add(nodeD);
            Assert.Equal(1, newList.Count);
            Assert.Equal("D", newList.ToFullString());

            newList = list.AddRange(new[] { nodeD, nodeE });
            Assert.Equal(2, newList.Count);
            Assert.Equal("D,E", newList.ToFullString());

            newList = list.Insert(0, nodeD);
            Assert.Equal(1, newList.Count);
            Assert.Equal("D", newList.ToFullString());

            newList = list.InsertRange(0, new[] { nodeD, nodeE });
            Assert.Equal(2, newList.Count);
            Assert.Equal("D,E", newList.ToFullString());

            newList = list.Remove(nodeD);
            Assert.Equal(0, newList.Count);

            Assert.Equal(-1, list.IndexOf(nodeD));
            Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(0));
            Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(1, nodeD));
            Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, nodeD));
            Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(1, new[] { nodeD }));
            Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(-1, new[] { nodeD }));
            Assert.Throws<ArgumentNullException>(() => list.Add(null));
            Assert.Throws<ArgumentNullException>(() => list.AddRange((IEnumerable<SyntaxNode>)null));
            Assert.Throws<ArgumentNullException>(() => list.Insert(0, null));
            Assert.Throws<ArgumentNullException>(() => list.InsertRange(0, (IEnumerable<SyntaxNode>)null));
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:37,代码来源:SeparatedSyntaxListTests.cs

示例8: ObjectCreationExpression

        public static string ObjectCreationExpression(ObjectCreationExpressionSyntax expression)
        {
            //Name all the arguments, since Swift usually requires named arguments when you create new objects.
            //Thanks! http://stackoverflow.com/questions/24174602/get-constructor-declaration-from-objectcreationexpressionsyntax-with-roslyn/24191494#24191494
            var symbol = Model.GetSymbolInfo(expression).Symbol as IMethodSymbol;

            var namedArgumentsList = new SeparatedSyntaxList<ArgumentSyntax>();

            for (var i = 0; i < expression.ArgumentList.Arguments.Count; i++)
            {
                var oldArgumentSyntax = expression.ArgumentList.Arguments[i];
                var parameterName = symbol.Parameters[i].Name;

                var nameColonSyntax = SyntaxFactory
                    .NameColon(SyntaxFactory.IdentifierName(parameterName))
                    .WithTrailingTrivia(SyntaxFactory.Whitespace(" "));

                var namedArgumentSyntax = SyntaxFactory.Argument(nameColonSyntax, oldArgumentSyntax.RefOrOutKeyword, oldArgumentSyntax.Expression);

                namedArgumentsList = namedArgumentsList.Add(namedArgumentSyntax);
            }

            //NOTE: this takes out expression.parent and everything, and probably screws with SyntaxModel stuff to
            return SyntaxNode(expression.Type) + SyntaxNode(SyntaxFactory.ArgumentList(namedArgumentsList));
        }
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:25,代码来源:ExpressionSyntaxParser.cs

示例9: CreateRegister

            // creates a correct register statement
            protected internal static SyntaxNode CreateRegister(SyntaxGenerator generator, MethodDeclarationSyntax declaration, string methodName)
            {
                var argument1 = generator.Argument(generator.IdentifierName(methodName)) as ArgumentSyntax;
                var argument2 = generator.Argument(generator.MemberAccessExpression(generator.IdentifierName("SyntaxKind"), "IfStatement")) as ArgumentSyntax;
                SeparatedSyntaxList<ArgumentSyntax> arguments = new SeparatedSyntaxList<ArgumentSyntax>();
                arguments = arguments.Add(argument1);
                arguments = arguments.Add(argument2);
                ArgumentListSyntax argumentList = SyntaxFactory.ArgumentList(arguments);

                string parameterName = GetFirstParameterName(declaration);
                SyntaxNode invocationExpr = BuildRegister(generator, parameterName, "RegisterSyntaxNodeAction", argumentList);
                return invocationExpr;
            }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:14,代码来源:CodeFixProvider.cs

示例10: AddIsNaNIssue

 static CodeAction AddIsNaNIssue(Document document, SemanticModel semanticModel, SyntaxNode root, BinaryExpressionSyntax node, ExpressionSyntax argExpr, string floatType)
 {
     return CodeActionFactory.Create(node.Span, DiagnosticSeverity.Warning, string.Format(node.IsKind(SyntaxKind.EqualsExpression) ? "Replace with '{0}.IsNaN(...)' call" : "Replace with '!{0}.IsNaN(...)' call", floatType), token =>
     {
         SyntaxNode newRoot;
         ExpressionSyntax expr;
         var arguments = new SeparatedSyntaxList<ArgumentSyntax>();
         arguments = arguments.Add(SyntaxFactory.Argument(argExpr));
         expr = SyntaxFactory.InvocationExpression(
             SyntaxFactory.MemberAccessExpression(
                 SyntaxKind.SimpleMemberAccessExpression,
                 SyntaxFactory.ParseExpression(floatType),
                 SyntaxFactory.IdentifierName("IsNaN")
             ),
             SyntaxFactory.ArgumentList(
                 arguments
             )
         );
         if (node.IsKind(SyntaxKind.NotEqualsExpression))
             expr = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, expr);
         expr = expr.WithAdditionalAnnotations(Formatter.Annotation);
         newRoot = root.ReplaceNode((SyntaxNode)node, expr);
         return Task.FromResult(document.WithSyntaxRoot(newRoot));
     });
 }
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:25,代码来源:CompareOfFloatsByEqualityOperatorCodeFixProvider.cs

示例11: AddCompareIssue

 static CodeAction AddCompareIssue(Document document, SemanticModel semanticModel, SyntaxNode root, BinaryExpressionSyntax node, string floatType)
 {
     return CodeActionFactory.Create(node.Span, DiagnosticSeverity.Warning, "Fix floating point number comparison", token =>
     {
         SyntaxNode newRoot;
         ExpressionSyntax expr;
         var arguments = new SeparatedSyntaxList<ArgumentSyntax>();
         arguments = arguments.Add(SyntaxFactory.Argument(SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, node.Left, node.Right)));
         expr = SyntaxFactory.BinaryExpression(
                 node.IsKind(SyntaxKind.EqualsExpression) ? SyntaxKind.LessThanExpression : SyntaxKind.GreaterThanExpression,
             SyntaxFactory.InvocationExpression(
                 SyntaxFactory.MemberAccessExpression(
                     SyntaxKind.SimpleMemberAccessExpression,
                     SyntaxFactory.ParseExpression("System.Math"),
                     SyntaxFactory.IdentifierName("Abs")
                 ),
                 SyntaxFactory.ArgumentList(
                     arguments
                 )
             ),
             SyntaxFactory.IdentifierName("EPSILON")
         );
         expr = expr.WithAdditionalAnnotations(Formatter.Annotation);
         newRoot = root.ReplaceNode((SyntaxNode)node, expr);
         return Task.FromResult(document.WithSyntaxRoot(newRoot));
     });
 }
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:27,代码来源:CompareOfFloatsByEqualityOperatorCodeFixProvider.cs

示例12: CreateClass

		static ITypeSymbol CreateClass (MonoDevelop.Projects.Project project, Stetic.ActionGroupComponent group, string name, string namspace, string folder)
		{
			string fullName = namspace.Length > 0 ? namspace + "." + name : name;
			
			var type = SyntaxFactory.ClassDeclaration (name)
				.AddBaseListTypes (SyntaxFactory.SimpleBaseType (SyntaxFactory.ParseTypeName ("Gtk.ActionGroup")));
			
			// Generate the constructor. It contains the call that builds the widget.
			var members = new SyntaxList<MemberDeclarationSyntax> ();
			
			var ctor = SyntaxFactory.ConstructorDeclaration (
				new SyntaxList<AttributeListSyntax> (),
				SyntaxFactory.TokenList (SyntaxFactory.Token (SyntaxKind.PublicKeyword)),
				SyntaxFactory.Identifier (name),
				SyntaxFactory.ParameterList (),
				SyntaxFactory.ConstructorInitializer (SyntaxKind.BaseKeyword, SyntaxFactory.ArgumentList (new SeparatedSyntaxList<ArgumentSyntax> { SyntaxFactory.Argument (SyntaxFactory.ParseExpression (fullName)) } )),
				SyntaxFactory.Block (
					SyntaxFactory.ExpressionStatement (
						SyntaxFactory.InvocationExpression (
							SyntaxFactory.ParseExpression ("Stetic.Gui.Build"),
							SyntaxFactory.ArgumentList (
								new SeparatedSyntaxList<ArgumentSyntax> {
									SyntaxFactory.Argument (SyntaxFactory.ThisExpression ()),
									SyntaxFactory.Argument (SyntaxFactory.ParseExpression (fullName))
								}
							)
						) 
					)
				)
			);
			
			type = type.AddMembers (ctor);
			
			// Add signal handlers
			foreach (Stetic.ActionComponent action in group.GetActions ()) {
				foreach (Stetic.Signal signal in action.GetSignals ()) {
					
					var parameters = new SeparatedSyntaxList<ParameterSyntax> ();
					foreach (var p in signal.SignalDescriptor.HandlerParameters) {
						parameters = parameters.Add (SyntaxFactory.Parameter (new SyntaxList<AttributeListSyntax> (), SyntaxFactory.TokenList (), SyntaxFactory.ParseTypeName (p.TypeName), SyntaxFactory.Identifier (p.Name), null)); 
					}
					
					var met = SyntaxFactory.MethodDeclaration (
				          new SyntaxList<AttributeListSyntax> (),
				          SyntaxFactory.TokenList (SyntaxFactory.Token (SyntaxKind.ProtectedKeyword)),
				          SyntaxFactory.ParseTypeName (signal.SignalDescriptor.HandlerReturnTypeName),
				          null,
				          SyntaxFactory.Identifier (signal.Handler),
				          null,
				          SyntaxFactory.ParameterList (parameters),
				          new SyntaxList<TypeParameterConstraintClauseSyntax> (),
				          SyntaxFactory.Block (),
				          null
			          );
					
						
					type = type.AddMembers (met);
				}
			}
			
			// Create the class
			return CodeGenerationService.AddType ((DotNetProject)project, folder, namspace, type);
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:63,代码来源:ActionGroupDisplayBinding.cs

示例13: ConsumeName

        private static NameSyntax ConsumeName(List<SyntaxToken> tokens, bool canBeGlobal = false)
        {
            // If we're here, we know the first token is a valid identifier
            var identifier = tokens.First ();
            tokens.RemoveAt (0);

            // The only valid next thing could be open parenthesis + "Of" for generic
            if (tokens.Count < 2)
                return Syntax.IdentifierName (identifier);

            if (tokens.First ().Kind != SyntaxKind.OpenParenToken)
                return CreateIdentifer (identifier, canBeGlobal);

            if (tokens.ElementAt (1).Kind != SyntaxKind.OfKeyword)
                return Syntax.IdentifierName (identifier);

            var open_param = tokens.First ();
            tokens.RemoveAt (0);

            var of_keyword = tokens.First ();
            tokens.RemoveAt (0);

            // Parse generic arguments
            var arguments = new SeparatedSyntaxList<TypeSyntax> ();

            while (true) {
                // Get a generic argument type
                var type = ConsumeQualifiedName (tokens);
                arguments.Add (type);

                // No closing parenthesis, return a IsMissing one
                if (tokens.Count == 0)
                    return Syntax.GenericName (identifier, Syntax.TypeArgumentList (open_param, of_keyword, arguments, Syntax.MissingToken (SyntaxKind.CloseParenToken)));

                var token = tokens.First ();

                // We hit a closing parenthesis, return our generic name
                if (token.Kind == SyntaxKind.CloseParenToken) {
                    tokens.RemoveAt (0);
                    return Syntax.GenericName (identifier, Syntax.TypeArgumentList (open_param, of_keyword, arguments, token));
                }

                // We hit a comma, store it and restart to find the next token
                if (token.Kind == SyntaxKind.CommaToken) {
                    tokens.RemoveAt (0);
                    arguments.Add (token);
                } else {
                    // Something else we don't handle, add a missing close parenthesis and return
                    var missing_token = Syntax.MissingToken (SyntaxKind.CloseParenToken);
                    return Syntax.GenericName (identifier, Syntax.TypeArgumentList (open_param, of_keyword, arguments, missing_token));
                }
            }
        }
开发者ID:jpobst,项目名称:Mokii,代码行数:53,代码来源:NameParser.cs

示例14: ConsumeQualifiedName

        private static NameSyntax ConsumeQualifiedName(List<SyntaxToken> tokens)
        {
            var list = new SeparatedSyntaxList<NameSyntax> ();
            var last_was_dot = true;
            var can_be_global = true;

            // Get all the name pieces and dot tokens
            while (true) {
                var token = tokens.First ();

                if (token.Kind == SyntaxKind.DotToken) {
                    // Handle a malformed case of starting with a period
                    if (list.Count == 0) {
                        var missing_token = Syntax.MissingToken (SyntaxKind.IdentifierToken);
                        tokens.Insert (0, missing_token);

                        var name = ConsumeName (tokens);
                        list.Add (name);
                        can_be_global = false;
                    }

                    // Remove the dot from tokens and add it to syntax list
                    tokens.RemoveAt (0);
                    list.Add (token);

                    // Implicit continuation after dot
                    while (tokens.Count > 0 && tokens.First ().Kind == SyntaxKind.StatementTerminatorToken) {
                        var term = tokens.First ();
                        tokens.RemoveAt (0);
                    }

                    last_was_dot = true;
                } else if (IsValidIdentifier (token) && last_was_dot) {
                    // Remove the name from tokens and add it to syntax list
                    var name = ConsumeName (tokens, can_be_global);
                    list.Add (name);
                    last_was_dot = false;
                    can_be_global = false;
                } else if (token.Kind == SyntaxKind.OpenParenToken && list.Count == 0) {
                    // Handle a malformed case with nothing before the open parenthesis
                    var missing_token = Syntax.MissingToken (SyntaxKind.IdentifierToken);
                    tokens.Insert (0, missing_token);

                    var name = ConsumeName (tokens);
                    list.Add (name);
                    last_was_dot = false;
                } else {
                    break;
                }
            }

            // No valid name case
            if (list.Count == 0) {
                var missing_token = Syntax.MissingToken (SyntaxKind.IdentifierToken);
                tokens.Insert (0, missing_token);
                list.Add (ConsumeName (tokens));
            }

            // Trails with a period and no valid identifier after
            if (list.Count == list.SeparatorCount) {
                var missing_token = Syntax.MissingToken (SyntaxKind.IdentifierToken);
                tokens.Insert (0, missing_token);
                list.Add (ConsumeName (tokens));
            }

            // Build them into a QualifiedNameSyntax
            return BuildQualifiedSyntax (list);
        }
开发者ID:jpobst,项目名称:Mokii,代码行数:68,代码来源:NameParser.cs


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