Class Pattern<T>
Defines a pattern for a specific type of value.
public abstract record Pattern<T> : Pattern, IEquatable<Pattern>, IEquatable<Pattern<T>>
Type Parameters
TThe type ofthe value to match on
- Inheritance
-
Pattern<T>
- Implements
-
IEquatable<Pattern<T>>
- Derived
- Inherited Members
Constructors
Pattern()
protected Pattern()
Pattern(Pattern<T>)
protected Pattern(Pattern<T> original)
Parameters
originalPattern<T>
Properties
EqualityContract
protected override Type EqualityContract { get; }
Property Value
Methods
AsObject()
Wraps the pattern into a more generalized Pattern<T>.
public override Pattern<object?> AsObject()
Returns
Equals(Pattern?)
public override sealed bool Equals(Pattern? other)
Parameters
otherPattern
Returns
Equals(Pattern<T>?)
public virtual bool Equals(Pattern<T>? other)
Parameters
otherPattern<T>
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
Format(IndentedTextWriter)
Serializes the pattern to a readable string.
public abstract void Format(IndentedTextWriter writer)
Parameters
writerIndentedTextWriterThe output stream.
GetHashCode()
public override int GetHashCode()
Returns
IsMatch(T, MatchingContext)
Gets a value indicating the provided input matches the pattern.
public bool IsMatch(T input, MatchingContext context)
Parameters
inputTThe input to match.
contextMatchingContextThe context in which to match the pattern to.
Returns
- bool
trueif the input matches the pattern,falseotherwise.
Match(T, MatchingContext)
Attempts to match the provided input to the pattern.
public abstract IMatchNode<T>? Match(T input, MatchingContext context)
Parameters
inputTThe input to match.
contextMatchingContextThe context in which to match the pattern to.
Returns
- IMatchNode<T>
When successful, returns the root node of the match tree, otherwise
null.
PrintMembers(StringBuilder)
protected override bool PrintMembers(StringBuilder builder)
Parameters
builderStringBuilder
Returns
ToString()
public override sealed string ToString()
Returns
Operators
operator &(Pattern<T>, Pattern<T>)
Combines two patterns into a pattern where both patterns should be satisfied.
public static Pattern<T> operator &(Pattern<T> a, Pattern<T> b)
Parameters
Returns
- Pattern<T>
The resulting pattern.
operator |(Pattern<T>, Pattern<T>)
Combines two patterns into a pattern where at least one should be satisfied.
public static Pattern<T> operator |(Pattern<T> a, Pattern<T> b)
Parameters
Returns
- Pattern<T>
The resulting pattern.
operator ==(Pattern<T>?, Pattern<T>?)
public static bool operator ==(Pattern<T>? left, Pattern<T>? right)
Parameters
Returns
operator !=(Pattern<T>?, Pattern<T>?)
public static bool operator !=(Pattern<T>? left, Pattern<T>? right)