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


C# Syntax.CompilationUnitSyntax类代码示例

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


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

示例1: RemovePrivateMethods

        static CompilationUnitSyntax RemovePrivateMethods(CompilationUnitSyntax root)
        {
            List<SyntaxNode> removes = new List<SyntaxNode>();

            var classes = root.DescendantNodes().OfType<ClassDeclarationSyntax>();

            foreach (var @class in classes)
            {
                var methods = @class.Members.OfType<MethodDeclarationSyntax>();
                foreach (var method in methods)
                {
                    SyntaxTokenList modifiers = method.Modifiers;
                    bool result = false;
                    foreach (SyntaxToken m in modifiers)
                    {
                        if (m.Text.Equals("private"))
                        {
                            result = true;
                            removes.Add(method);
                            break;
                        }
                    }
                        
                }
            }

            root = root.RemoveNodes(removes,SyntaxRemoveOptions.KeepDirectives);

            return root;
        }
开发者ID:AliSepehri,项目名称:RoslynCodeModifier,代码行数:30,代码来源:Program.cs

示例2: 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

示例3: ImplementNotifyPropertyChangedAsync

 private async Task<Document> ImplementNotifyPropertyChangedAsync(Document document, CompilationUnitSyntax root, SemanticModel model, IEnumerable<ExpandablePropertyInfo> properties, CancellationToken cancellationToken)
 {
     document = document.WithSyntaxRoot(CodeGeneration.ImplementINotifyPropertyChanged(root, model, properties, document.Project.Solution.Workspace));
     document = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
     document = await Formatter.FormatAsync(document, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
     return document;
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:CodeRefactoringProvider.cs

示例4: ParseFileContent

        private static SyntaxElement[] ParseFileContent(CompilationUnitSyntax root, SemanticCache semanticCache)
        {
            var walker = new FileSyntaxWalker(semanticCache);
            walker.Visit(root);

            return walker.ResultsAccumulator.GetResults();
        }
开发者ID:pgrefviau,项目名称:SourceMaster,代码行数:7,代码来源:SourceParsingManager.cs

示例5: AddRequiredUsings

        static CompilationUnitSyntax AddRequiredUsings(CompilationUnitSyntax root)
        {
            NameSyntax name = SyntaxFactory.IdentifierName(" System");
            if (root.Usings.Contains(SyntaxFactory.UsingDirective(name)) == false)
                return root.AddUsings(SyntaxFactory.UsingDirective(name));

            return root;
        }
开发者ID:AliSepehri,项目名称:RoslynCodeModifier,代码行数:8,代码来源:Program.cs

示例6: VisitCompilationUnit

			public override void VisitCompilationUnit (CompilationUnitSyntax node)
			{
				var startNode = node.DescendantNodesAndSelf (n => region.Start <= n.SpanStart).FirstOrDefault ();
				if (startNode == node || startNode == null) {
					base.VisitCompilationUnit (node);
				} else {
					this.Visit (startNode);
				}
			}
开发者ID:michaelc37,项目名称:monodevelop,代码行数:9,代码来源:CSharpNavigationTextEditorExtension.cs

示例7: VisitCompilationUnit

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

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

示例8: AddMethodTo

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

示例9: VisitCompilationUnit

 public override void VisitCompilationUnit(CompilationUnitSyntax node)
 {
     foreach (MemberDeclarationSyntax member in node.Members)
     {
         if (member.Kind() == SyntaxKind.GlobalStatement)
         {
             Visit(member);
         }
     }
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:10,代码来源:LocalBinderFactory.cs

示例10: GetExistingNamespaces

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

            return q.ToList();
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:UsingDirectivesAdder.cs

示例11: GetImport

        private IEnumerable<string> GetImport(CompilationUnitSyntax root)
        {
            List<string> result = new List<string>();

            foreach (var import in root.Usings)
            {
                result.Add(import.Name.ToFullString());
            }

            return result;
        }
开发者ID:fendy3002,项目名称:MapperGenerator,代码行数:11,代码来源:SourceCodeToFileModelConverter.cs

示例12: AddNamedTypeTo

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

示例13: GetIssuesInternal

    private IEnumerable<Microsoft.CodeAnalysis.CodeActions.CodeIssue> GetIssuesInternal(IEnumerable<ClousotOutput> results, CompilationUnitSyntax compilationUnitDeclaration)
    {
      IEnumerator<ClousotOutput> enumerator;

      try
      {
        enumerator = results.GetEnumerator();
      }
      catch
      {
        yield break;
      }

      bool hasNext;

      try
      {
        hasNext = enumerator.MoveNext();
      }
      catch
      {
        yield break;
      }

      while (hasNext)
      {
        var result = enumerator.Current;
        
        //foreach (var result in results )
        {
          var msg = result.Message;
          var span = result.Span;
          var action = result.action;
          if (span.IsEmpty)
          {
            msg = "Unknown location: " + msg;
            span = compilationUnitDeclaration.GetFirstToken().Span;
          }
          if (action == null)
            yield return new Microsoft.CodeAnalysis.CodeActions.CodeIssue(Microsoft.CodeAnalysis.CodeActions.CodeIssueKind.Warning, span, msg);
          else
            yield return new Microsoft.CodeAnalysis.CodeActions.CodeIssue(Microsoft.CodeAnalysis.CodeActions.CodeIssueKind.Warning, span, msg, action);
        }
        try
        {
          hasNext = enumerator.MoveNext();
        }
        catch
        {
          yield break;
        }
      }
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:53,代码来源:CodeIssueProvider.cs

示例14: AddPropertyTo

        internal static CompilationUnitSyntax AddPropertyTo(
            CompilationUnitSyntax destination,
            IPropertySymbol property,
            CodeGenerationOptions options,
            IList<bool> availableIndices)
        {
            var declaration = GeneratePropertyOrIndexer(property, CodeGenerationDestination.CompilationUnit, options);

            var members = Insert(destination.Members, declaration, options,
                availableIndices, after: LastPropertyOrField, before: FirstMember);
            return destination.WithMembers(members);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:12,代码来源:PropertyGenerator.cs

示例15: ShouldUseSmartTokenFormatterInsteadOfIndenter

        public static bool ShouldUseSmartTokenFormatterInsteadOfIndenter(
            IEnumerable<IFormattingRule> formattingRules,
            CompilationUnitSyntax root,
            TextLine line,
            OptionSet optionSet,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(formattingRules);
            Contract.ThrowIfNull(root);

            if (!optionSet.GetOption(FeatureOnOffOptions.AutoFormattingOnReturn, LanguageNames.CSharp))
            {
                return false;
            }

            if (optionSet.GetOption(FormattingOptions.SmartIndent, LanguageNames.CSharp) != FormattingOptions.IndentStyle.Smart)
            {
                return false;
            }

            var firstNonWhitespacePosition = line.GetFirstNonWhitespacePosition();
            if (!firstNonWhitespacePosition.HasValue)
            {
                return false;
            }

            var token = root.FindToken(firstNonWhitespacePosition.Value);
            if (token.IsKind(SyntaxKind.None) ||
                token.SpanStart != firstNonWhitespacePosition)
            {
                return false;
            }

            // first see whether there is a line operation for current token
            var previousToken = token.GetPreviousToken(includeZeroWidth: true);

            // only use smart token formatter when we have two visible tokens.
            if (previousToken.Kind() == SyntaxKind.None || previousToken.IsMissing)
            {
                return false;
            }

            var lineOperation = FormattingOperations.GetAdjustNewLinesOperation(formattingRules, previousToken, token, optionSet);
            if (lineOperation == null || lineOperation.Option == AdjustNewLinesOption.ForceLinesIfOnSingleLine)
            {
                // no indentation operation, nothing to do for smart token formatter
                return false;
            }

            // We're pressing enter between two tokens, have the formatter figure out hte appropriate
            // indentation.
            return true;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:53,代码来源:CSharpIndentationService.cs


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