Table of Contents

Class Pattern

Namespace
CilFi.Patterns
Assembly
CilFi.Core.dll

Defines a pattern for a specific object.

public abstract record Pattern : IEquatable<Pattern>
Inheritance
Pattern
Implements
Derived
Inherited Members

Constructors

Pattern(Pattern)

protected Pattern(Pattern original)

Parameters

original Pattern

Properties

EqualityContract

protected virtual Type EqualityContract { get; }

Property Value

Type

IsAny

Gets a value indicating this pattern matches any object of the intended type.

public virtual bool IsAny { get; }

Property Value

bool

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

values IEnumerable<Pattern<T>>

The options

Returns

Pattern<T>

The pattern.

Type Parameters

T

The 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

values IEnumerable<Pattern<T>>

The options

Returns

Pattern<T>

The pattern.

Type Parameters

T

The 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

values IEnumerable<Pattern<T>>

The options

Returns

Pattern<T>

The pattern.

Type Parameters

T

The 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

T

The type to match on.

AsObject()

Wraps the pattern into an instance of a Pattern<T>

public abstract Pattern<object?> AsObject()

Returns

Pattern<object>

Equals(Pattern?)

public virtual bool Equals(Pattern? other)

Parameters

other Pattern

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

List<T>(IEnumerable<Pattern<T>>)

Constructs a list pattern.

public static ReadOnlyListPattern<T> List<T>(IEnumerable<Pattern<T>> sequence)

Parameters

sequence IEnumerable<Pattern<T>>

The sequence pattern.

Returns

ReadOnlyListPattern<T>

The pattern.

Type Parameters

T

The 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

value T

The value the input should match on.

Returns

Pattern<T>

The pattern.

Type Parameters

T

The 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

values IEnumerable<T>

The values the input should match on.

Returns

IList<Pattern<T>>

The pattern.

Type Parameters

T

The 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

T

The 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

T

The 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

predicate Predicate<T>

The predicate.

Returns

Pattern<T>

The pattern.

Type Parameters

T

The type of the value to match.

PrintMembers(StringBuilder)

protected virtual bool PrintMembers(StringBuilder builder)

Parameters

builder StringBuilder

Returns

bool

Regex(string)

Constructs the pattern that matches on strings following a specific regular expression.

public static RegexPattern Regex(string pattern)

Parameters

pattern string

The regular expression.

Returns

RegexPattern

The pattern.

ToString()

public override string ToString()

Returns

string

Operators

operator ==(Pattern?, Pattern?)

public static bool operator ==(Pattern? left, Pattern? right)

Parameters

left Pattern
right Pattern

Returns

bool

operator !=(Pattern?, Pattern?)

public static bool operator !=(Pattern? left, Pattern? right)

Parameters

left Pattern
right Pattern

Returns

bool