1 // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. 2 3 using System.Collections.Generic; 4 using System.Diagnostics.CodeAnalysis; 5 using System.Linq; 6 using System.Web.Razor.Parser.SyntaxTree; 7 using System.Web.Razor.Text; 8 9 namespace System.Web.Razor.Tokenizer.Symbols 10 { 11 public static class SymbolExtensions 12 { GetContent(this SpanBuilder span)13 public static LocationTagged<string> GetContent(this SpanBuilder span) 14 { 15 return GetContent(span, e => e); 16 } 17 18 [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "Func<T> is the recommended type for generic delegates and requires this level of nesting")] GetContent(this SpanBuilder span, Func<IEnumerable<ISymbol>, IEnumerable<ISymbol>> filter)19 public static LocationTagged<string> GetContent(this SpanBuilder span, Func<IEnumerable<ISymbol>, IEnumerable<ISymbol>> filter) 20 { 21 return GetContent(filter(span.Symbols), span.Start); 22 } 23 GetContent(this IEnumerable<ISymbol> symbols, SourceLocation spanStart)24 public static LocationTagged<string> GetContent(this IEnumerable<ISymbol> symbols, SourceLocation spanStart) 25 { 26 if (symbols.Any()) 27 { 28 return new LocationTagged<string>(String.Concat(symbols.Select(s => s.Content)), spanStart + symbols.First().Start); 29 } 30 else 31 { 32 return new LocationTagged<string>(String.Empty, spanStart); 33 } 34 } 35 GetContent(this ISymbol symbol)36 public static LocationTagged<string> GetContent(this ISymbol symbol) 37 { 38 return new LocationTagged<string>(symbol.Content, symbol.Start); 39 } 40 } 41 } 42