简体   繁体   中英

Roslyn C# Get the symbol definition from another class

I have the following invocation in my document:

var myContext = new FeatureWorkflowContext(FeatureWorkflowIds.CanvasConfig, activator);

Using Roslyn I have successfully found the first argument

FeatureWorkflowIds.CanvasConfig

Now I would like to get it real value defined in the FeatureWorkflowIds.cs class as

public static readonly string CanvasConfig = "Feature.WorkflowName.CanvasConfig";

My goal is to simply find the "Feature.WorkflowName.CanvasConfig" string.

Is there a simple way of getting this done or I have to open the FeatureWorkflowIds class and search through the Syntax tree?

If the field were const like this:

public const string CanvasConfig = "Feature.WorkflowName.CanvasConfig";

It would be easy to use the SemanticModel and get the constant value.

However, since it is not const, merely static readonly, you indeed have no other option but to investigate the source declaration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM