Class Pattern
Defines a pattern for a specific object.
public abstract record Pattern : IEquatable<Pattern>
- Inheritance
-
Pattern
- Implements
- Derived
-
Pattern<T>
- Inherited Members
Constructors
Pattern(Pattern)
protected Pattern(Pattern original)
Parameters
originalPattern
Properties
EqualityContract
protected virtual Type EqualityContract { get; }
Property Value
IsAny
Gets a value indicating this pattern matches any object of the intended type.
public virtual bool IsAny { get; }
Property Value
Methods
AllNonNull<T>(IEnumerable<Pattern<T>?>)
Constructs a pattern that requires all the provided non-null option patterns to be satisfied.
public static Pattern<T> AllNonNull<T>(IEnumerable<Pattern<T>?> values)
Parameters
valuesIEnumerable<Pattern<T>>The options
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type of the value to match.
AllOf<T>(IEnumerable<Pattern<T>>)
Constructs a pattern that requires all the provided option patterns to be satisfied.
public static Pattern<T> AllOf<T>(IEnumerable<Pattern<T>> values)
Parameters
valuesIEnumerable<Pattern<T>>The options
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type of the value to match.
AnyOf<T>(IEnumerable<Pattern<T>>)
Constructs a pattern that requires at least one of the provided option patterns to be satisfied.
public static Pattern<T> AnyOf<T>(IEnumerable<Pattern<T>> values)
Parameters
valuesIEnumerable<Pattern<T>>The options
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type of the value to match.
Any<T>()
Gets the pattern that matches on any instance of the provided type. This includes null/default instances.
public static Pattern<T?> Any<T>()
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type to match on.
AsObject()
Wraps the pattern into an instance of a Pattern<T>
public abstract Pattern<object?> AsObject()
Returns
Equals(Pattern?)
public virtual bool Equals(Pattern? other)
Parameters
otherPattern
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetHashCode()
public override int GetHashCode()
Returns
List<T>(IEnumerable<Pattern<T>>)
Constructs a list pattern.
public static ReadOnlyListPattern<T> List<T>(IEnumerable<Pattern<T>> sequence)
Parameters
sequenceIEnumerable<Pattern<T>>The sequence pattern.
Returns
- ReadOnlyListPattern<T>
The pattern.
Type Parameters
TThe type of the value to match.
Literal<T>(T)
Constructs the pattern that matches on a specific concrete value of the provided type.
public static Pattern<T> Literal<T>(T value)
Parameters
valueTThe value the input should match on.
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type of the value to match.
Literals<T>(IEnumerable<T>)
Wraps the provided values into literal patterns.
public static IList<Pattern<T>> Literals<T>(IEnumerable<T> values)
Parameters
valuesIEnumerable<T>The values the input should match on.
Returns
Type Parameters
TThe type of the value to match.
NotNull<T>()
Gets the pattern that matches on any non-null instance of the provided type.
public static Pattern<T?> NotNull<T>()
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type to match on.
Null<T>()
Gets the pattern that matches on a null instance of the provided type.
public static Pattern<T?> Null<T>()
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type to match on.
Predicate<T>(Predicate<T>)
Constructs a pattern that matches on an input satisfying the provided predicate.
public static Pattern<T> Predicate<T>(Predicate<T> predicate)
Parameters
predicatePredicate<T>The predicate.
Returns
- Pattern<T>
The pattern.
Type Parameters
TThe type of the value to match.
PrintMembers(StringBuilder)
protected virtual bool PrintMembers(StringBuilder builder)
Parameters
builderStringBuilder
Returns
Regex(string)
Constructs the pattern that matches on strings following a specific regular expression.
public static RegexPattern Regex(string pattern)
Parameters
patternstringThe regular expression.
Returns
- RegexPattern
The pattern.
ToString()
public override string ToString()
Returns
Operators
operator ==(Pattern?, Pattern?)
public static bool operator ==(Pattern? left, Pattern? right)
Parameters
Returns
operator !=(Pattern?, Pattern?)
public static bool operator !=(Pattern? left, Pattern? right)