Class Parser
Represents code used to parse values into concrete types.
Wraps a static method, a constructor taking a single
ReadOnlySpan(char), a constuctor taking a ReadOnlySpan(char)
and a ReadContext, or a delegate.
Inheritance
System.Object
Parser
Namespace: Cesil
Assembly: Cesil.dll
Syntax
public sealed class Parser : Object, IElseSupporting<Parser>, IEquatable<Parser>, ICreatesCacheableDelegate<Parser.DynamicParserDelegate>
Methods
AllowNullValues()
Returns a Parser that differs from this by explicitly allowing
null values to be created by it.
Declaration
public Parser AllowNullValues()
Returns
Else(Parser)
Create a new parser that will try this parser, but if it returns false
it will then try the given fallback Parser.
Declaration
public Parser Else(Parser fallbackParser)
Parameters
Type |
Name |
Description |
Parser |
fallbackParser |
|
Returns
Equals(Parser)
Returns true if the given Parser is equivalent to this one
Declaration
public bool Equals(Parser parser)
Parameters
Type |
Name |
Description |
Parser |
parser |
|
Returns
Type |
Description |
System.Boolean |
|
Equals(Object)
Returns true if the given object is equivalent to this one
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Boolean |
|
ForbidNullValues()
Returns a Parser that differs from this by explicitly forbidding
null values to be created by it.
If the .NET runtime cannot guarantee that nulls will not be created,
null checks will be injected.
Declaration
public Parser ForbidNullValues()
Returns
ForConstructor(ConstructorInfo)
Create a Parser from the given constructor.
The method must:
- take either a ReadOnlySpan(char)
or
- take parameters
- ReadOnlySpan(char)
- in ReadContext
Declaration
public static Parser ForConstructor(ConstructorInfo constructor)
Parameters
Type |
Name |
Description |
System.Reflection.ConstructorInfo |
constructor |
|
Returns
ForDelegate<TOutput>(ParserDelegate<TOutput>)
Create a Parser from the given delegate.
Declaration
public static Parser ForDelegate<TOutput>(ParserDelegate<TOutput> del)
Parameters
Returns
Type Parameters
Create a Parser from the given method.
The method must:
- be static
- return a bool
- have 3 parameters
- ReadOnlySpan(char)
- in ReadContext,
- out assignable to outputType
Declaration
public static Parser ForMethod(MethodInfo method)
Parameters
Type |
Name |
Description |
System.Reflection.MethodInfo |
method |
|
Returns
GetDefault(TypeInfo)
Returns the default parser for the given type, if any exists.
Declaration
public static Parser GetDefault(TypeInfo forType)
Parameters
Type |
Name |
Description |
System.Reflection.TypeInfo |
forType |
|
Returns
GetHashCode()
Returns a stable hash for this Parser.
Declaration
public override int GetHashCode()
Returns
Type |
Description |
System.Int32 |
|
ToString()
Describes this Parser.
This is provided for debugging purposes, and the format is not guaranteed to be stable between releases.
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Operators
Equality(Parser, Parser)
Compare two Parsers for equality
Declaration
public static bool operator ==(Parser a, Parser b)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Explicit(Delegate to Parser)
Convenience operator, equivalent to calling Parser.ForDelegate if non-null.
Returns null if del is null.
Declaration
public static explicit operator Parser(Delegate del)
Parameters
Type |
Name |
Description |
System.Delegate |
del |
|
Returns
Explicit(ConstructorInfo to Parser)
Convenience operator, equivalent to calling Parser.ForConstructor if non-null.
Returns null if cons is null.
Declaration
public static explicit operator Parser(ConstructorInfo cons)
Parameters
Type |
Name |
Description |
System.Reflection.ConstructorInfo |
cons |
|
Returns
Explicit(MethodInfo to Parser)
Convenience operator, equivalent to calling Parser.ForMethod if non-null.
Returns null if method is null.
Declaration
public static explicit operator Parser(MethodInfo method)
Parameters
Type |
Name |
Description |
System.Reflection.MethodInfo |
method |
|
Returns
Inequality(Parser, Parser)
Compare two Parsers for inequality
Declaration
public static bool operator !=(Parser a, Parser b)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Implements
System.IEquatable<>