问题
I can use a SyntaxGenerator to generate a parameter of type Int32 like so...
var generator = SyntaxGenerator.GetGenerator(document);
var paramType = generator.TypeExpression(SpecialType.System_Int32);
var param = generator.ParameterDeclaration("MyParam", paramType);
What equivalent code should I use to create a parameter of type Dataset?
I presume I need to create an ITypeSymbol to pass to the generator.TypeExpression, but how to do this?
回答1:
If you have access to a Compilation
, you can use GetTypeByMetadataName, as explained 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);
来源:https://stackoverflow.com/questions/43356807/how-to-create-a-roslyn-itypesymbol-for-an-arbitrary-type