using System; using System.Collections.Generic; using System.Linq; using System.Text; using Roslyn.Services.Editor; using Roslyn.Services; using Roslyn.Compilers.CSharp; using Roslyn.Compilers; using RoslynCTPLibrary.Attributes; using RoslynCTPLibrary.Extensions; using Roslyn.Compilers.Common; using System.Threading; namespace EventImplementer { [ExportSyntaxNodeOutliner(typeof(PropertyDeclarationSyntax))] class Outliner : ISyntaxOutliner { public IEnumerable<OutliningSpan> GetOutliningSpans(IDocument document, CommonSyntaxNode node, CancellationToken cancellationToken) { var property = (PropertyDeclarationSyntax)node; if (!property.Attributes.Any(ad => ad.Attributes.Any(a => a.Name.PlainName == typeof(FiresEventOnChange).Name || a.Name.PlainName == typeof(FiresEventOnQuery).Name))) yield break; var field = property.GetOwnerType().Members.OfType<FieldDeclarationSyntax>().FirstOrDefault(f => Constants.FieldPrefix + property.Identifier.ValueText == f.Declaration.Variables.First().Identifier.ValueText); if (field == null) yield break; var whiteSpace = ""; foreach (var ws in property.GetLeadingTrivia().Where(t => t.Kind == SyntaxKind.WhitespaceTrivia)) for (int i = 0; i < ws.Width; i++) whiteSpace += " "; yield return new OutliningSpan(TextSpan.FromBounds(property.Identifier.Span.End + 2, field.Span.End), whiteSpace + "{ get; set; }", true); } #region Unimplemented ISyntaxOutliner members public IEnumerable<OutliningSpan> GetOutliningSpans(IDocument document, CommonSyntaxTrivia trivia, CancellationToken cancellationToken) { throw new NotImplementedException(); } #endregion } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)