Skip to content

Roslyn syntax tree service

Vladimir Shkolka edited this page Jul 23, 2017 · 2 revisions

Description

Gets syntax tree where current adaptation attribute was defined.

Definition

Type definition page.

Requirements

Key

typeof(Microsoft.CodeAnalysis.SyntaxTree)

Example

Prints syntax tree file source path

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
[Designer("PS.Build.Adaptation")]
public class AdaptationAttribute : Attribute
{
    #region Members

    private void PreBuild(IServiceProvider provider)
    {
        var tree = (SyntaxTree)provider.GetService(typeof(SyntaxTree));
        if (Debugger.IsAttached)
        {
            Debug.WriteLine(tree.FilePath);
        }
    }

    #endregion
}