microsoft / microsoft/typespec

[http-client-csharp] TypeProvider should support generics so is its produced CSharpType

Open
#8,164 4 comments 0 reactions 0 assignees View on GitHub
emitter:client:csharp
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

Here is throwing an exception: https://github.com/microsoft/typespec/blob/a87e8874f4ba5373d7653b73582f7df21c6f5f4e/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Primitives/CSharpType.cs#L499
saying TypeProvider does not support generics.
But actually TypeProvider supports generics. We have a method `GetTypeArguments` to allow us to have a TypeProvider that supports multiple generic arguments.

This issue is found when we are trying to write this in our xml doc:
```
internal class ManagementLongRunningOperationProvider : TypeProvider
{
// this generated class could have a generic argument
protected override FormattableString BuildDescription() => $"{Type:C}";
}
```
and this exception was thrown.

Here is a stack trace:
```
StackTrace:
TypeProvider doesn't support generics.
at Microsoft.TypeSpec.Generator.Primitives.CSharpType.GetGenericTypeDefinition()
at Microsoft.TypeSpec.Generator.CodeWriter.AppendTypeForCRef(CSharpType type)
at Microsoft.TypeSpec.Generator.CodeWriter.Append(FormattableString formattableString)
at Microsoft.TypeSpec.Generator.CodeWriter.Append(FormattableString formattableString)
at Microsoft.TypeSpec.Generator.CodeWriter.WriteLine(FormattableString formattableString)
at Microsoft.TypeSpec.Generator.Statements.XmlDocStatement.WriteSingleLine(CodeWriter writer)
at Microsoft.TypeSpec.Generator.Statements.XmlDocStatement.Write(CodeWriter writer)
at Microsoft.TypeSpec.Generator.CodeWriter.WriteXmlDocsNoScope(XmlDocProvider docs)
at Microsoft.TypeSpec.Generator.CodeWriter.WriteXmlDocs(XmlDocProvider docs)
at Microsoft.TypeSpec.Generator.CodeWriter.WriteConstructor(ConstructorProvider ctor)
at Microsoft.TypeSpec.Generator.Primitives.TypeProviderWriter.WriteConstructors(CodeWriter writer)
at Microsoft.TypeSpec.Generator.Primitives.TypeProviderWriter.WriteClassOrStructContent(CodeWriter writer)
at Microsoft.TypeSpec.Generator.Primitives.TypeProviderWriter.WriteType(CodeWriter writer)
at Microsoft.TypeSpec.Generator.Primitives.TypeProviderWriter.Write()
at Microsoft.TypeSpec.Generator.CSharpGen.ExecuteAsync()
at Microsoft.TypeSpec.Generator.GeneratorRunner.RunAsync(CommandLineOptions options)
at Microsoft.TypeSpec.Generator.Program.Run(CommandLineOptions options, GeneratorRunner runner)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.