I have MethodDeclarationSyntax
or IMethodSymbol
, but I could not find any way, how to access formatted method name:
namespace XXX.YYY.ZZZ
{
public class MyClass
{
public void MyMethod()
{
}
}
}
But all I can access are texts formatted like this:
public System.Void XXX.YYY.ZZZ.MyClass.MyMethod()
I saw some examples with Formatter.Format
. But they all need document/workspace etc and I am not interested to get adjustable formatting based on solution or VS Setting, but simple common C# general formatting for method signature:
public void MyMethod()
Very much same with parameters in other cases:
public System.Void XXX.YYY.ZZZ.MyClass.MyMethod(System.Sting myString, System.Int
index)
Is there some way to do that in Roslyn?
It seems that the trick is the difference between what the Roslyn object show in debugging mode and what they actually provide with ToString() methods.
Sometimes namespace is part of the output for Identifier names, but mostly not, yet object representation can mislead in debugging mode.
The best way is to obtain the string by ToString or other means in first place, even when a variable, field or constant is showing in debug mode something else:).