Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class ConstructorProviderHelpers
public static ConstructorProvider BuildMockingConstructor(TypeProvider enclosingType)
{
return new ConstructorProvider(
new ConstructorSignature(enclosingType.Type, $"Initializes a new instance of {enclosingType.Name} for mocking.", MethodSignatureModifiers.Protected, []),
new ConstructorSignature(enclosingType.Type, $"Initializes a new instance of the <see cref=\"{enclosingType.Name}\"/> class for mocking.", MethodSignatureModifiers.Protected, []),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the format specifier :C to generate crefs.
We could use :C when the argument is a System.Type or CSharpType.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to implement the :C format specifier as requested, but encountered an issue with generic types. When using {enclosingType.Type:C}, the generator crashes for generic types like MgmtTypeSpecArmOperation<T> with the error "TypeProvider doesn't support generics" at CSharpType.GetGenericTypeDefinition().

Could you clarify how to handle generic types with the :C format specifier? Should we:

  1. Use a conditional approach to detect generic types and fall back to manual formatting?
  2. Is there a different way to use :C with generic types?
  3. Or should we use :C only for non-generic types?

I've reverted to the manual approach for now to maintain functionality while waiting for guidance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot could you do it any way so that I could see the error message and find if there is a workaround of it?
If there is a bug on this API, then we could first put aside the topic of other ctors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented the :C format specifier as requested (commit e1d17fb). The error with generic types is now reproduced:

TypeProvider doesn't support generics.
   at Microsoft.TypeSpec.Generator.Primitives.CSharpType.GetGenericTypeDefinition()
   at Microsoft.TypeSpec.Generator.CodeWriter.AppendTypeForCRef(CSharpType type)

The issue occurs when the :C formatter calls AppendTypeForCRef which then calls GetGenericTypeDefinition() on generic types like MgmtTypeSpecArmOperation<T>. This method is not supported for generics.

new MethodBodyStatement[] { MethodBodyStatement.Empty },
enclosingType);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.