简体   繁体   中英

Is there a way to lookup the C# alias keyword for a given special type?

I'm writing a Roslyn Source Generator which generates code based on the members of a specified interface.

For example, given the following interface:

interface IFoo
{
    string Bar { get; set; }
}

I want to generate (within other code) the following property:

string IFoo.Bar { get; set; }

So far, I'm able to generate this:

System.String IFoo.Bar { get; set; }

which would work, but is there a way to use the string keyword, given that I don't know until runtime, when I'm analysing a particular interface type, what the type will actually be?

I've got the INamedTypeSymbol representing the System.String type. Is there a way to lookup a language keyword based on this?

I just discovered that ((INamedTypeSymbol)namedType).ToDisplayString() appears to give me what I want.

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