How do I create a Roslyn ITypeSymbol for an arbitrary type?
I can use SyntaxGenerator to generate an Int32 type parameter like ...
var generator = SyntaxGenerator.GetGenerator(document);
var paramType = generator.TypeExpression(SpecialType.System_Int32);
var param = generator.ParameterDeclaration("MyParam", paramType);
What is the equivalent code to use to create a parameter of type Dataset ?
I am assuming I need to create an ITypeSymbol in order to navigate to the .TypeExpression generator , but how do I do that?
+3
source to share
1 answer
If you have access to Compilation
, you can use GetTypeByMetadataName
as described in this blog post and this SO answer ::
var dataSetType = compilation.GetTypeByMetadataName("System.Data.DataSet");
var paramType = generator.TypeExpression(dataSetType);
var param = generator.ParameterDeclaration("MyParam", paramType);
+1
source to share