-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor fluent generator API to explicit Method().WithParameter().WithReturnType() chain
#18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,44 @@ public static class Generate | |
| { | ||
| public static IGeneratorsFactory CurrentGenerator { get; set; } = new RecordingGeneratorsFactory(); | ||
|
|
||
| public static IMethodImplementationGenerator MethodImplementation() => CurrentGenerator.CreateImplementation(); | ||
| public static IMethodImplementationGenerator<TReturnType> MethodImplementation<TReturnType>() => CurrentGenerator.CreateImplementation<TReturnType>(); | ||
| public static IMethodImplementationGenerator<TArg1, TReturnType> MethodImplementation<TArg1, TReturnType>() => CurrentGenerator.CreateImplementation<TArg1, TReturnType>(); | ||
| public static IMethodBuilder Method() => new MethodBuilder(CurrentGenerator); | ||
| } | ||
|
|
||
| public interface IMethodBuilder | ||
| { | ||
| IMethodBuilder<TArg1> WithParameter<TArg1>(); | ||
| IMethodImplementationGenerator<TReturnType> WithReturnType<TReturnType>(); | ||
| } | ||
|
|
||
| public interface IMethodBuilder<TArg1> | ||
| { | ||
| IMethodImplementationGenerator<TArg1, TReturnType> WithReturnType<TReturnType>(); | ||
| } | ||
|
|
||
| public class MethodBuilder : IMethodBuilder | ||
| { | ||
| private readonly IGeneratorsFactory _generatorsFactory; | ||
|
|
||
| public MethodBuilder(IGeneratorsFactory generatorsFactory) | ||
| { | ||
| _generatorsFactory = generatorsFactory; | ||
| } | ||
|
|
||
| public IMethodBuilder<TArg1> WithParameter<TArg1>() => new MethodBuilder<TArg1>(_generatorsFactory); | ||
|
|
||
| public IMethodImplementationGenerator<TReturnType> WithReturnType<TReturnType>() => _generatorsFactory.CreateImplementation<TReturnType>(); | ||
| } | ||
|
|
||
| public class MethodBuilder<TArg1> : IMethodBuilder<TArg1> | ||
| { | ||
| private readonly IGeneratorsFactory _generatorsFactory; | ||
|
|
||
| public MethodBuilder(IGeneratorsFactory generatorsFactory) | ||
| { | ||
| _generatorsFactory = generatorsFactory; | ||
| } | ||
|
|
||
| public IMethodImplementationGenerator<TArg1, TReturnType> WithReturnType<TReturnType>() => _generatorsFactory.CreateImplementation<TArg1, TReturnType>(); | ||
| } | ||
|
Comment on lines
+21
to
45
|
||
|
|
||
| public class EmptyGeneratorsFactory : IGeneratorsFactory | ||
|
|
@@ -40,4 +75,4 @@ public interface IGeneratorsFactory | |
| IMethodImplementationGenerator CreateImplementation(); | ||
| IMethodImplementationGenerator<TReturnType> CreateImplementation<TReturnType>(); | ||
| IMethodImplementationGenerator<TArg1, TReturnType> CreateImplementation<TArg1, TReturnType>(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Generate.Method().WithReturnType<TReturnType>()(no-parameter) path is part of the new fluent entrypoint, but current tests only exercise the.WithParameter<TArg1>().WithReturnType<TReturnType>()chain. Adding at least one test that uses the parameterless chain (similar toColorsClassFluent) would help catch regressions in this new API surface.