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


C# NamespaceDeclarationSyntax.AddMembers方法代码示例

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


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

示例1: Go

        private static NamespaceDeclarationSyntax Go(NamespaceDeclarationSyntax ns, Configuration config, Specification spec)
        {
            var className = ClassNameNormaliser(spec.Info.Title);

            var constructorCode = [email protected]"if (!string.IsNullOrWhiteSpace(url)){{ this.url = url;}} else {{ this.url = ""{spec.Schemes[0]}://{spec.Host}""; }}";
            if (config.IncludeHTTPClientForCSharp)
            {
                constructorCode += Environment.NewLine + " if (httpClient == null){ this.httpClient = new SwaggerHTTPClient();} else { this.httpClient = httpClient; }";
            }

            var baseClass = SyntaxFactory.ClassDeclaration(className)
                .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
                .AddMembers(Field("url", "string").AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)),
                            Field("httpClient", "ISwaggerHTTPClient").AddModifiers(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)),
                Constructor(className, constructorCode, new SimplifiedParameter("url", "string", "null", true), new SimplifiedParameter("httpClient", "ISwaggerHTTPClient", config.IncludeHTTPClientForCSharp ? "null" : null, true)))
                .WithCloseBraceToken(SyntaxFactory.Token(SyntaxKind.CloseBraceToken));

            if (spec.Definations != null)
            {
                foreach (var defination in spec.Definations)
                {
                    baseClass = AddDefination(baseClass, defination, config);
                }
            }

            foreach (var path in spec.Paths)
            {
                baseClass = AddOperation(baseClass, OperationConfig.FromValues(HTTPAction.Delete, path.Delete, path.Path), config);
                baseClass = AddOperation(baseClass, OperationConfig.FromValues(HTTPAction.Get, path.Get, path.Path), config);
                baseClass = AddOperation(baseClass, OperationConfig.FromValues(HTTPAction.Post, path.Post, path.Path), config);
                baseClass = AddOperation(baseClass, OperationConfig.FromValues(HTTPAction.Put, path.Put, path.Path), config);
                baseClass = AddOperation(baseClass, OperationConfig.FromValues(HTTPAction.Head, path.Head, path.Path), config);
                baseClass = AddOperation(baseClass, OperationConfig.FromValues(HTTPAction.Options, path.Options, path.Path), config);
                baseClass = AddOperation(baseClass, OperationConfig.FromValues(HTTPAction.Patch, path.Patch, path.Path), config);
            }

            if (config.IncludeHTTPClientForCSharp)
            {
                baseClass = baseClass.WithTrailingTrivia(SyntaxFactory.Comment(httpCode));
            }

            return ns.AddMembers(baseClass);
        }
开发者ID:rmaclean,项目名称:nSwagger,代码行数:43,代码来源:CSharpGenerator.cs


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