本文整理汇总了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;
}
示例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);
}
}
}
示例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;
}
示例4: ParseFileContent
private static SyntaxElement[] ParseFileContent(CompilationUnitSyntax root, SemanticCache semanticCache)
{
var walker = new FileSyntaxWalker(semanticCache);
walker.Visit(root);
return walker.ResultsAccumulator.GetResults();
}
示例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;
}
示例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);
}
}
示例7: VisitCompilationUnit
public override SyntaxNode VisitCompilationUnit(CompilationUnitSyntax node)
{
if (node.Usings.Any() || node.Externs.Any())
{
node = node.WithAdditionalAnnotations(LayoutAnnotations.MultiLineConstructAnnotation);
}
return base.VisitCompilationUnit(node);
}
示例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());
}
示例9: VisitCompilationUnit
public override void VisitCompilationUnit(CompilationUnitSyntax node)
{
foreach (MemberDeclarationSyntax member in node.Members)
{
if (member.Kind() == SyntaxKind.GlobalStatement)
{
Visit(member);
}
}
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
}
}
示例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);
}
示例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;
}