-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIMethodBodyGeneratorSwitchBody.cs
More file actions
31 lines (26 loc) · 1.48 KB
/
IMethodBodyGeneratorSwitchBody.cs
File metadata and controls
31 lines (26 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace EasySourceGenerators.Abstractions;
// ReSharper disable TypeParameterCanBeVariant - variance removed for simplicity
public interface IMethodBodyGeneratorSwitchBody<TParam1, TReturnType>
{
IMethodBodyGeneratorSwitchBodyCase<TParam1, TReturnType> ForCases(params object[] cases);
IMethodBodyGeneratorSwitchBodyDefaultCase<TParam1, TReturnType> ForDefaultCase();
}
public interface IMethodBodyGeneratorSwitchBodyCase<TParam1, TReturnType>
{
/// <summary>
/// Specific case(s) will use the body provided.
/// </summary>
/// <param name="body">During code generation this body will be emitted.</param>
IMethodBodyGeneratorSwitchBody<TParam1, TReturnType> UseProvidedBody(Func<TParam1, TReturnType> body);
/// <summary>
/// Specify case(s) will return a constant value.
/// </summary>
/// <param name="constantValueFactory">During code generation, this delegate will be run to calculate the constant value.
/// The delegate will not be used in the generated code. Only the value it produces after it's executed during code generation.</param>
IMethodBodyGeneratorSwitchBody<TParam1, TReturnType> ReturnConstantValue(Func<TParam1, TReturnType> constantValueFactory);
}
public interface IMethodBodyGeneratorSwitchBodyDefaultCase<TParam1, TReturnType> : IMethodBodyGenerator
{
IMethodBodyGenerator UseProvidedBody(Func<TParam1, TReturnType> body);
IMethodBodyGenerator ReturnConstantValue(Func<TParam1, TReturnType> constantValueFactory);
}