• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Syntax.NamespaceDeclarationSyntax类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GetUsingsSpan

		private static TextSpan GetUsingsSpan(CompilationUnitSyntax root, NamespaceDeclarationSyntax namespaceDeclaration)
		{
			if (namespaceDeclaration != null)
			{
				var usings = namespaceDeclaration.Usings;
				var start = usings.First().SpanStart;
				var end = usings.Last().Span.End;
				return TextSpan.FromBounds(start, end);
			}
			else
			{
				var rootUsings = root.Usings;
				if (rootUsings.Any())
				{
					var start = rootUsings.First().SpanStart;
					var end = rootUsings.Last().Span.End;
					return TextSpan.FromBounds(start, end);
				}
				else
				{
					var start = 0;
					var end = root.Members.Any()
						? root.Members.First().GetFirstToken().Span.End
						: root.Span.End;
					return TextSpan.FromBounds(start, end);
				}
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:28,代码来源:CompilationUnitSyntaxExtensions.cs


示例2: VisitNamespaceDeclaration

 //protected override void VisitInvocationExpression(InvocationExpressionSyntax node)
 //{
    
 //}
 public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
 {
     foreach (var type in node.DescendantNodes().OfType<ClassDeclarationSyntax>())
     {
         Visit(type);
     }
 }
开发者ID:jjrdk,项目名称:CqrsMessagingTools,代码行数:11,代码来源:MilSyntaxWalker.cs


示例3: VisitNamespaceDeclaration

 public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
 {
     var semanticModel = Context.Instance.Compilation.GetSemanticModel(node.SyntaxTree);
     var symbol = semanticModel.GetDeclaredSymbol(node);
     var fullName = symbol.GetFullName();
     ProcessNamespace(fullName);
 }
开发者ID:x335,项目名称:WootzJs,代码行数:7,代码来源:NamespaceTransformer.cs


示例4: VisitNamespaceDeclaration

        public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            string ns = node.Name.ToFullString();//Extend: seems no need to further break down.
            var template = _template.CreateNamespaceTemplate();
            template.Assign(NamespaceTemplate.NAMESPACE, ns);
            if (!RegisteredNamespace.Contains(ns))
            {
                _output.WriteLine(node.Name, template.GetBeginString());
            }

            foreach (var member in node.Members)
            {
                var info = _semanticModel.GetDeclaredSymbol(member);
                if (info.IsNoCompile())
                    continue;

                this.Visit(member);
            }

            if (!RegisteredNamespace.Contains(ns))
            {
                _output.TrivialWriteLine(template.GetEndString());
                RegisteredNamespace.Add(ns);
            }

            return node;
        }
开发者ID:rexzh,项目名称:SharpJs,代码行数:27,代码来源:Rewriter_BasicStructure.cs


示例5: AddParameterClassToNamespaceAndUpdateClassToUseNamespace

 private static NamespaceDeclarationSyntax AddParameterClassToNamespaceAndUpdateClassToUseNamespace(NamespaceDeclarationSyntax oldNamespace, ClassDeclarationSyntax oldClass, MethodDeclarationSyntax oldMethod)
 {
     var className = $"NewClass{oldMethod.Identifier.Text}";
     var newParameterClass = CreateParameterClass(className, oldMethod);
     var newNamespace = oldNamespace.ReplaceNode(oldClass, UpdateClassToUseNewParameterClass(className, oldClass, oldMethod))
         .AddMembers(newParameterClass);
     return newNamespace;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:8,代码来源:ParameterRefactoryCodeFixProvider.cs


示例6: VisitNamespaceDeclaration

        public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            if (node.Usings.Any() || node.Externs.Any())
            {
                node = node.WithAdditionalAnnotations(LayoutAnnotations.MultiLineConstructAnnotation);
            }

            return base.VisitNamespaceDeclaration(node);
        }
开发者ID:madelson,项目名称:MedallionCodeFormatter,代码行数:9,代码来源:MultiLineConstructAnnotator.cs


示例7: AddMethodTo

 internal static NamespaceDeclarationSyntax AddMethodTo(
     NamespaceDeclarationSyntax destination,
     IMethodSymbol method,
     CodeGenerationOptions options,
     IList<bool> availableIndices)
 {
     var declaration = GenerateMethodDeclaration(method, CodeGenerationDestination.Namespace, options);
     var members = Insert(destination.Members, declaration, options, availableIndices, after: LastMethod);
     return destination.WithMembers(members.ToSyntaxList());
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:MethodGenerator.cs


示例8: VisitNamespaceDeclaration

        /// <summary>Called when the visitor visits a NamespaceDeclarationSyntax node.</summary>
        public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            var u = _namespaces.Select(each => SyntaxFactory.UsingDirective(SyntaxFactory.ParseName($" {each}"))
                .WithLeadingTrivia(_leadingTrivia)
                .WithTrailingTrivia(_trailingTrivia)
            ).ToArray();

            node = node.AddUsings(u);
            node = node.WithUsings(Sort(node.Usings));
            return base.VisitNamespaceDeclaration(node);
        }
开发者ID:devigned,项目名称:autorest,代码行数:12,代码来源:AddUsingsRewriter.cs


示例9: AddNamedTypeTo

 public static NamespaceDeclarationSyntax AddNamedTypeTo(
     ICodeGenerationService service,
     NamespaceDeclarationSyntax destination,
     INamedTypeSymbol namedType,
     CodeGenerationOptions options,
     IList<bool> availableIndices)
 {
     var declaration = GenerateNamedTypeDeclaration(service, namedType, CodeGenerationDestination.Namespace, options);
     var members = Insert(destination.Members, declaration, options, availableIndices);
     return ConditionallyAddFormattingAnnotationTo(
         destination.WithMembers(members),
         members);
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:13,代码来源:NamedTypeGenerator.cs


示例10: GenerateClasses

        public static MemberDeclarationSyntax[] GenerateClasses(NamespaceDeclarationSyntax @namespace)
        {
            var isInterfaceToClass = @namespace.GetLeadingTrivia().Any(trivia => trivia.ToString().Trim() == "//Meta(interface-to-class)");
            if (!isInterfaceToClass)
                return Array<MemberDeclarationSyntax>.Empty;

            var resultMembers = new List<MemberDeclarationSyntax>();
            foreach (var @interface in @namespace.Members.OfType<InterfaceDeclarationSyntax>())
            {
                resultMembers.Add(ToClass(@interface));
            }
            return resultMembers.ToArray();
        }
开发者ID:Serj-Tm,项目名称:NitroBolt.CodeGeneration,代码行数:13,代码来源:InterfaceToClassGenerator.cs


示例11: NewNameSpaceFactory

 private static NamespaceDeclarationSyntax NewNameSpaceFactory(NamespaceDeclarationSyntax OldNameSpace, ClassDeclarationSyntax OldClass, MethodDeclarationSyntax OldMethod)
 {
     var newNameSpace = OldNameSpace;
     var className = $"NewClass{OldMethod.Identifier.Text}";
     var memberNameSpaceOld = (from member in OldNameSpace.Members
                               where member == OldClass
                               select member).FirstOrDefault();
     newNameSpace = OldNameSpace.ReplaceNode(memberNameSpaceOld, NewClassFactory(className, OldClass, OldMethod));
     var newParameterClass = NewClassParameterFactory(className, NewPropertyClassFactory(OldMethod));
     newNameSpace = newNameSpace
                     .WithMembers(newNameSpace.Members.Add(newParameterClass))
                     .WithAdditionalAnnotations(Formatter.Annotation);
     return newNameSpace;
 }
开发者ID:nikolasmagno,项目名称:code-cracker,代码行数:14,代码来源:ParameterRefactoryCodeFixProvider.cs


示例12: AddNamespaceTo

        public static NamespaceDeclarationSyntax AddNamespaceTo(
            ICodeGenerationService service,
            NamespaceDeclarationSyntax destination,
            INamespaceSymbol @namespace,
            CodeGenerationOptions options,
            IList<bool> availableIndices)
        {
            var declaration = GenerateNamespaceDeclaration(service, @namespace, options);
            if (!(declaration is NamespaceDeclarationSyntax))
            {
                throw new ArgumentException(CSharpWorkspaceResources.NamespaceCanNotBeAddedIn);
            }

            var members = Insert(destination.Members, (NamespaceDeclarationSyntax)declaration, options, availableIndices);
            return destination.WithMembers(members);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:16,代码来源:NamespaceGenerator.cs


示例13: VisitNamespaceDeclaration

            public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
            {
                var result = (NamespaceDeclarationSyntax)base.VisitNamespaceDeclaration(node);
                if (!_namespacesToImport.TryGetValue(node, out var namespaces))
                {
                    return result;
                }

                if (!result.CanAddUsingDirectives(_cancellationToken))
                {
                    return result;
                }

                var directives = CreateDirectives(namespaces);
                return result.AddUsingDirectives(directives, _placeSystemNamespaceFirst, Formatter.Annotation);
            }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:16,代码来源:UsingDirectivesAdder.Rewriter.cs


示例14: VisitNamespaceDeclaration

    public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
    {
      var parts = node.Name.ToString().Split('.');
      cb.AppendIndent();
      foreach (var part in parts)
      {
        cb.Append("namespace ").Append(part).Append(" { ");
      }
      cb.AppendLine();

      base.VisitNamespaceDeclaration(node);

      cb.AppendIndent();
      foreach (var part in parts)
        cb.Append("} /* " + part + "*/ ");
      cb.AppendLine();
    }
开发者ID:codedecay,项目名称:Blackmire,代码行数:17,代码来源:CppHeaderWalker.cs


示例15: VisitNamespaceDeclaration

        public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            var identifierName = SyntaxFactory.IdentifierName(_typeNamespace);
            var newNamespace = SyntaxFactory.NamespaceDeclaration(identifierName);

            var newNode =  node.Update(
                node.NamespaceKeyword,
                newNamespace.Name,
                node.OpenBraceToken,
                node.Externs,
                node.Usings,
                node.Members,
                node.CloseBraceToken,
                node.SemicolonToken);

            return base.VisitNamespaceDeclaration(newNode);
        }
开发者ID:laurentkempe,项目名称:Furnace,代码行数:17,代码来源:FurnaceTypeWriter.cs


示例16: GetExistingNamespaces

        private IList<INamespaceSymbol> GetExistingNamespaces(
            SemanticModel semanticModel, NamespaceDeclarationSyntax namespaceDeclaration, CancellationToken cancellationToken)
        {
            var q = from u in namespaceDeclaration.Usings
                    let symbol = semanticModel.GetSymbolInfo(u.Name, cancellationToken).Symbol as INamespaceSymbol
                    where symbol != null && !symbol.IsGlobalNamespace
                    select symbol;

            var usingImports = q.ToList();

            var namespaceSymbol = semanticModel.GetDeclaredSymbol(namespaceDeclaration, cancellationToken) as INamespaceSymbol;
            var namespaceImports = GetContainingNamespacesAndThis(namespaceSymbol).ToList();

            var outerNamespaces = this.GetExistingNamespaces(semanticModel, namespaceDeclaration.Parent, cancellationToken);

            return outerNamespaces.Concat(namespaceImports).Concat(usingImports)
                                  .Distinct()
                                  .OrderBy(INamespaceSymbolExtensions.CompareNamespaces)
                                  .ToList();
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:20,代码来源:UsingDirectivesAdder.cs


示例17: FixBadNamespace

        private async Task<Solution> FixBadNamespace(Document document, NamespaceDeclarationSyntax namespaceDecl, CancellationToken cancellationToken)
        {
            try
            {
                var newName = GetNamespaceName(document.Project, document.Folders);

                var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
                INamespaceSymbol nsSymbol = semanticModel.GetDeclaredSymbol(namespaceDecl, cancellationToken);
                Solution originalSolution = document.Project.Solution;
                OptionSet optionSet = originalSolution.Workspace.Options;

                var newSolution = await Renamer.RenameSymbolAsync(originalSolution, nsSymbol, newName, optionSet, cancellationToken).ConfigureAwait(false);

                return newSolution;
            }
            catch (OperationCanceledException ocex)
            {
                Debug.WriteLine(ocex.Message);
                return document.Project.Solution;
            }
        }
开发者ID:jquintus,项目名称:RoslynNamespaceAnalyzer,代码行数:21,代码来源:CodeFixProvider.cs


示例18: GetNamespaceId

        private static int GetNamespaceId(SyntaxNode container, NamespaceDeclarationSyntax target, ref int index)
        {
            var compilation = container as CompilationUnitSyntax;
            if (compilation != null)
            {
                return GetNamespaceId(compilation.Members, target, ref index);
            }

            var @namespace = container as NamespaceDeclarationSyntax;
            if (@namespace != null)
            {
                return GetNamespaceId(@namespace.Members, target, ref index);
            }

            return Contract.FailWithReturn<int>("shouldn't reach here");
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:16,代码来源:ExpressionSyntaxExtensions.cs


示例19: RegisterNamespaceDeclarationCodeFix

 private SyntaxNode RegisterNamespaceDeclarationCodeFix(SyntaxNode syntaxRoot, NamespaceDeclarationSyntax node, IndentationOptions indentationOptions)
 {
     return this.ReformatElement(syntaxRoot, node, node.OpenBraceToken, node.CloseBraceToken, indentationOptions);
 }
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:4,代码来源:SA1502CodeFixProvider.cs


示例20: GetDeclaredSymbol

        /// <summary>
        /// Given a namespace declaration syntax node, get the corresponding namespace symbol for the declaration
        /// assembly.
        /// </summary>
        /// <param name="declarationSyntax">The syntax node that declares a namespace.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The namespace symbol that was declared by the namespace declaration.</returns>
        public override INamespaceSymbol GetDeclaredSymbol(NamespaceDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
        {
            CheckSyntaxNode(declarationSyntax);

            return GetDeclaredNamespace(declarationSyntax);
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:13,代码来源:SyntaxTreeSemanticModel.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Syntax.ParameterSyntax类代码示例发布时间:2022-05-26
下一篇:
C# Syntax.NameSyntax类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap