-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- no constructor analysis if static factories are not generated
- fix case where parameters of derived type come from different syntax tree - valid code generated for uniontype without cases
- Loading branch information
Showing
8 changed files
with
178 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...st/Snapshots/Run_union_type_generator.For_union_type_without_derived_types.00.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//HintName: Attributes.g.cs | ||
using System; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace FunicularSwitch.Generators | ||
{ | ||
/// <summary> | ||
/// Mark an abstract partial type with a single generic argument with the ResultType attribute. | ||
/// This type from now on has Ok | Error semantics with map and bind operations. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class, Inherited = false)] | ||
sealed class ResultTypeAttribute : Attribute | ||
{ | ||
public ResultTypeAttribute() => ErrorType = typeof(string); | ||
public ResultTypeAttribute(Type errorType) => ErrorType = errorType; | ||
|
||
public Type ErrorType { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Mark a static method or a member method or you error type with the MergeErrorAttribute attribute. | ||
/// Static signature: TError -> TError -> TError. Member signature: TError -> TError | ||
/// We are now able to collect errors and methods like Validate, Aggregate, FirstOk that are useful to combine results are generated. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
sealed class MergeErrorAttribute : Attribute | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Mark a static method with the ExceptionToError attribute. | ||
/// Signature: Exception -> TError | ||
/// This method is always called, when an exception happens in a bind operation. | ||
/// So a call like result.Map(i => i/0) will return an Error produced by the factory method instead of throwing the DivisionByZero exception. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
sealed class ExceptionToError : Attribute | ||
{ | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...st/Snapshots/Run_union_type_generator.For_union_type_without_derived_types.01.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//HintName: Attributes.g.cs | ||
using System; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace FunicularSwitch.Generators | ||
{ | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)] | ||
sealed class UnionTypeAttribute : Attribute | ||
{ | ||
public CaseOrder CaseOrder { get; set; } = CaseOrder.Alphabetic; | ||
public bool StaticFactoryMethods { get; set; } = true; | ||
} | ||
|
||
enum CaseOrder | ||
{ | ||
Alphabetic, | ||
AsDeclared, | ||
Explicit | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Class, Inherited = false)] | ||
sealed class UnionCaseAttribute : Attribute | ||
{ | ||
public UnionCaseAttribute(int index) => Index = index; | ||
|
||
public int Index { get; } | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...st/Snapshots/Run_union_type_generator.For_union_type_without_derived_types.02.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//HintName: Attributes.g.cs | ||
using System; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace FunicularSwitch.Generators | ||
{ | ||
[AttributeUsage(AttributeTargets.Enum)] | ||
sealed class ExtendedEnumAttribute : Attribute | ||
{ | ||
public EnumCaseOrder CaseOrder { get; set; } = EnumCaseOrder.AsDeclared; | ||
public ExtensionAccessibility Accessibility { get; set; } = ExtensionAccessibility.Public; | ||
} | ||
|
||
enum EnumCaseOrder | ||
{ | ||
Alphabetic, | ||
AsDeclared | ||
} | ||
|
||
/// <summary> | ||
/// Generate match methods for all enums defined in assembly that contains AssemblySpecifier. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] | ||
class ExtendEnumsAttribute : Attribute | ||
{ | ||
public Type AssemblySpecifier { get; } | ||
public EnumCaseOrder CaseOrder { get; set; } = EnumCaseOrder.AsDeclared; | ||
public ExtensionAccessibility Accessibility { get; set; } = ExtensionAccessibility.Public; | ||
|
||
public ExtendEnumsAttribute() => AssemblySpecifier = typeof(ExtendEnumsAttribute); | ||
|
||
public ExtendEnumsAttribute(Type assemblySpecifier) | ||
{ | ||
AssemblySpecifier = assemblySpecifier; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Generate match methods for Type. Must be enum. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] | ||
class ExtendEnumAttribute : Attribute | ||
{ | ||
public Type Type { get; } | ||
|
||
public EnumCaseOrder CaseOrder { get; set; } = EnumCaseOrder.AsDeclared; | ||
|
||
public ExtensionAccessibility Accessibility { get; set; } = ExtensionAccessibility.Public; | ||
|
||
public ExtendEnumAttribute(Type type) | ||
{ | ||
Type = type; | ||
} | ||
} | ||
|
||
enum ExtensionAccessibility | ||
{ | ||
Internal, | ||
Public | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters