當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。