Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method in TypeFactory to get a ModelTypeProvider or EnumTypeProvider #3468

Closed
ArcturusZhang opened this issue May 29, 2024 · 1 comment
Closed
Assignees
Labels
emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Comments

@ArcturusZhang
Copy link
Member

We need to add a method such as GetModel or GetEnum to construct a modeltypeprovider or enumtypeprovider, so that plugin writer to replace our default implementation.

public abstract class TypeFactory
{
	public abstract ModelTypeProvider GetModel(InputModelType model);
	public abstract EnumTypeProvider GetEnum(InputEnumType enum);
}

public class ModelTypeProvider : TypeProvider {}
public abstract class EnumTypeProvider : TypeProvider {}
@ArcturusZhang ArcturusZhang added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label May 29, 2024
@ArcturusZhang
Copy link
Member Author

So we decided to make the APIs simple and lightweighted, since it is quite simple to do something like:

public class MyTypeFactory
{
	public override CSharpType CreateCSharpType(InputType inputType) => inputType switch {
		InputModelType model => new MyModel(model),
		_ => base.CreateCSharpType(inputType)
	};
}

to override the behavior of how to get the model, to make it simple, we do not need a method to specifically get a TypeProvider from a InputModelType.

@ArcturusZhang ArcturusZhang closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp
Projects
None yet
Development

No branches or pull requests

1 participant