SchemaBase Class

Base implementation for a based schema.

public abstract class SchemaBase : IYamlSchema
Implements

Constructors

NameDescription
SchemaBase()

SchemaBase()

SchemaBase.cs
protected SchemaBase()

No documentation is available.

Methods

NameDescription
AddScalarRule(Type[], string, string, Func<Match, object?>, Func<object, string>?)Adds a scalar resolution rule for one or more CLR types.
AddScalarRule<T>(string, string, Func<Match, T?>, Func<T, string>?)Add a tag resolution rule that is invoked when regex matches the Value of a Scalar node. The tag is resolved to tag and decode is invoked when actual value of type T is extracted from the node text.
ExpandTag(string?)Expands a short tag into its long form.
GetDefaultTag(MappingStart)Gets the default tag for a MappingStart event.
GetDefaultTag(NodeEvent)Gets default Tag.
GetDefaultTag(SequenceStart)Gets the default tag for a SequenceStart event.
GetDefaultTag(Type)Gets default Tag.
GetTypeForDefaultTag(string?)Gets type For Default Tag.
IsTagImplicit(string?)Determines whether tag Implicit.
PrepareScalarRules()Prepare scalar rules. In the implementation of this method, should call
RegisterDefaultTagMapping(string, Type, bool)Registers a default tag mapping for the specified CLR type.
RegisterDefaultTagMapping<T>(string, bool)Registers a default tag mapping for T.
RegisterTag(string, string)Registers a long/short tag association.
ShortenTag(string?)Converts a long tag into its short form.
TryParse(Scalar, bool, string?, object?)Tries to parse.
TryParse(Scalar, Type, object?)Tries to parse.

AddScalarRule overloads

AddScalarRule(Type[], string, string, Func<Match, object?>, Func<object, string>?)

SchemaBase.cs

Adds a scalar resolution rule for one or more CLR types.

protected void AddScalarRule(Type[] types, string tag, string regex, Func<Match, object?> decode, Func<object, string>? encode)
Parameters
types Type[]
tag string
regex string
decode Func<Match, object?>
encode Func<object, string>?

AddScalarRule<T>(string, string, Func<Match, T?>, Func<T, string>?)

SchemaBase.cs

Add a tag resolution rule that is invoked when regex matches the Value of a Scalar node. The tag is resolved to tag and decode is invoked when actual value of type T is extracted from the node text.

protected void AddScalarRule<T>(string tag, string regex, Func<Match, T?> decode, Func<T, string>? encode)
Type parameters
T
Type of the scalar
Parameters
tag string
The tag.
regex string
The regex.
decode Func<Match, T?>
The decode function.
encode Func<T, string>?
The encode function.
Example
private sealed class OnOffSchema : CoreSchema
{
    protected override void PrepareScalarRules()
    {
        base.PrepareScalarRules();

        // Resolve on/off as booleans, in addition to the rules of the core schema
        AddScalarRule("!!bool", "on|On|ON", _ => true, null);
        AddScalarRule("!!bool", "off|Off|OFF", _ => false, null);
    }
}

ExpandTag(string?)

SchemaBase.cs

Expands a short tag into its long form.

public string? ExpandTag(string? shortTag)

Parameters

shortTag string?

Returns

string?

GetDefaultTag overloads

GetDefaultTag(MappingStart)

Gets the default tag for a MappingStart event.

protected abstract string GetDefaultTag(MappingStart nodeEvent)
Parameters
nodeEvent MappingStart
The node event.
Returns

string The default tag for a map.

GetDefaultTag(NodeEvent)

SchemaBase.cs

Gets default Tag.

public string? GetDefaultTag(NodeEvent nodeEvent)
Parameters
nodeEvent NodeEvent
Returns

string?

GetDefaultTag(SequenceStart)

Gets the default tag for a SequenceStart event.

protected abstract string GetDefaultTag(SequenceStart nodeEvent)
Parameters
nodeEvent SequenceStart
The node event.
Returns

string The default tag for a seq.

GetDefaultTag(Type)

SchemaBase.cs

Gets default Tag.

public string? GetDefaultTag(Type type)
Parameters
type Type
Returns

string?

GetTypeForDefaultTag(string?)

SchemaBase.cs

Gets type For Default Tag.

public Type? GetTypeForDefaultTag(string? tag)

Parameters

tag string?

Returns

Type?

IsTagImplicit(string?)

SchemaBase.cs

Determines whether tag Implicit.

public bool IsTagImplicit(string? tag)

Parameters

tag string?

Returns

bool

PrepareScalarRules()

SchemaBase.cs

Prepare scalar rules. In the implementation of this method, should call

protected virtual void PrepareScalarRules()

RegisterDefaultTagMapping overloads

RegisterDefaultTagMapping(string, Type, bool)

SchemaBase.cs

Registers a default tag mapping for the specified CLR type.

protected void RegisterDefaultTagMapping(string tag, Type type, bool isDefault)
Parameters
tag string
type Type
isDefault bool

RegisterDefaultTagMapping<T>(string, bool)

SchemaBase.cs

Registers a default tag mapping for T.

protected void RegisterDefaultTagMapping<T>(string tag, bool isDefault = false)
Type parameters
T
Parameters
tag string
isDefault bool

RegisterTag(string, string)

SchemaBase.cs

Registers a long/short tag association.

public void RegisterTag(string shortTag, string longTag)

Parameters

shortTag string
The short tag.
longTag string
The long tag.

Exceptions

ArgumentNullException
shortTag or shortTag

ShortenTag(string?)

SchemaBase.cs

Converts a long tag into its short form.

public string? ShortenTag(string? tag)

Parameters

tag string?

Returns

string?

TryParse overloads

TryParse(Scalar, bool, string?, object?)

SchemaBase.cs

Tries to parse.

public virtual bool TryParse(Scalar scalar, bool decodeValue, out string? defaultTag, out object? value)
Parameters
scalar Scalar
decodeValue bool
defaultTag string?
value object?
Returns

bool

TryParse(Scalar, Type, object?)

SchemaBase.cs

Tries to parse.

public bool TryParse(Scalar scalar, Type type, out object? value)
Parameters
scalar Scalar
type Type
value object?
Returns

bool

Constants

NameDescription
StrLongTagThe string long tag: tag:yaml.org,2002:str
StrShortTagThe string short tag: !!str

StrLongTag

The string long tag: tag:yaml.org,2002:str

public const string StrLongTag = "tag:yaml.org,2002:str"

StrShortTag

The string short tag: !!str

public const string StrShortTag = "!!str"