forked from WalkerCodeRanger/ExhaustiveMatching
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for structurally detectable closed hierarchcies (Wa…
…lkerCodeRanger#42) Detecting closed hierarchies like discriminated unions without the need to provide [Closed]-Attribute
- Loading branch information
1 parent
bf60896
commit c5361a1
Showing
9 changed files
with
279 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
obj/ | ||
bin/ | ||
*.nupkg | ||
*.user | ||
*.user | ||
_ReSharper.Caches/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Examples { | ||
public abstract class Result<TSuccess, TError> : IEquatable<Result<TSuccess, TError>> | ||
{ | ||
private Result() { } | ||
|
||
public sealed class Success : Result<TSuccess, TError> | ||
{ | ||
public TSuccess Value { get; } | ||
|
||
public Success(TSuccess value) { Value = value; } | ||
|
||
public override bool Equals(Result<TSuccess, TError> other) | ||
{ | ||
return other is Success success && EqualityComparer<TSuccess>.Default.Equals(Value, success.Value); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return EqualityComparer<TSuccess>.Default.GetHashCode(Value); | ||
} | ||
} | ||
|
||
public sealed class Error : Result<TSuccess, TError> | ||
{ | ||
public TError Value { get; } | ||
|
||
public Error(TError value) { Value = value; } | ||
|
||
public override bool Equals(Result<TSuccess, TError> other) | ||
{ | ||
return other is Error error && EqualityComparer<TError>.Default.Equals(Value, error.Value); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return EqualityComparer<TError>.Default.GetHashCode(Value); | ||
} | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return obj is Result<TSuccess, TError> result && Equals(result); | ||
} | ||
|
||
public abstract override int GetHashCode(); | ||
|
||
public abstract bool Equals(Result<TSuccess, TError> other); | ||
|
||
public static bool operator ==(Result<TSuccess, TError> left, Result<TSuccess, TError> right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(Result<TSuccess, TError> left, Result<TSuccess, TError> right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
} | ||
} |