英文:
How to construct generic type from symbol info in roslyn
问题
INamedTypeSymbol - System.Action<MyAwsomeApp.Foo>
.
英文:
I have INamedTypeSymbol
, lets say MyAwsomeApp.Foo
. I would like to wrap it in Action<>
. How I can achieve this?
Expected output is INamedTypeSymbol - System.Action<MyAwseomeApp.Foo>
.
答案1
得分: 1
你可以使用 INamedType.Construct 方法来实现这个,例如:
var actionOfT = compilation.GetTypeByMetadataName(typeof(Action<>).FullName);
var foo = compilation.GetTypeByMetadataName("MyAwseomeApp.Foo");
var actionOfFoo = actionOfT.Construct(foo);
英文:
You can use the INamedType.Construct method for that, e.g.
var actionOfT = compilation.GetTypeByMetadataName(typeof(Action<>).FullName);
var foo = compilation.GetTypeByMetadataName("MyAwseomeApp.Foo");
var actionOfFoo = actionOfT.Construct(foo);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论