public void SetStaticConstructorBody(ImmutableArray <byte> il) { Debug.Assert(_methods is null); _methods = SpecializedCollections.SingletonReadOnlyList( new RootModuleStaticConstructor(containingTypeDefinition: this, il)); }
public IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerable <TextSpan>?spans, SyntaxFormattingOptions options, IEnumerable <AbstractFormattingRule>?rules, CancellationToken cancellationToken) { IReadOnlyList <TextSpan> spansToFormat; if (spans == null) { spansToFormat = node.FullSpan.IsEmpty ? SpecializedCollections.EmptyReadOnlyList <TextSpan>() : SpecializedCollections.SingletonReadOnlyList(node.FullSpan); } else { spansToFormat = new NormalizedTextSpanCollection(spans.Where(s_notEmpty)); } if (spansToFormat.Count == 0) { return(CreateAggregatedFormattingResult(node, SpecializedCollections.EmptyList <AbstractFormattingResult>())); } rules ??= GetDefaultFormattingRules(); List <AbstractFormattingResult>?results = null; foreach (var(startToken, endToken) in node.ConvertToTokenPairs(spansToFormat)) { if (node.IsInvalidTokenRange(startToken, endToken)) { continue; } results ??= new List <AbstractFormattingResult>(); results.Add(Format(node, options, rules, startToken, endToken, cancellationToken)); } // quick simple case check if (results == null) { return(CreateAggregatedFormattingResult(node, SpecializedCollections.EmptyList <AbstractFormattingResult>())); } if (results.Count == 1) { return(results[0]); } // more expensive case return(CreateAggregatedFormattingResult(node, results)); }