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


C# Syntax.NamespaceDeclarationSyntax类代码示例

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


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


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