Table of Contents

Class NeutralText

Namespace
L5Sharp.Common
Assembly
L5Sharp.dll

A wrapper class around the textual representation of the ladder logic notation called neutral text.

public sealed class NeutralText
Inheritance
NeutralText
Inherited Members

Remarks

Neutral text can represent a single instruction or a full rung (collection of instructions). Each instruction contains sets of tag names and values known as operands. This class provides functions for extracting the textual information into strongly type classes that are easier to work with.

Constructors

NeutralText(string)

Creates a new NeutralText object with the provided text input.

public NeutralText(string text)

Parameters

text string

A string input that represents a neutral text format.

Exceptions

ArgumentNullException

When text is null.

FormatException

When text is null.

See Also

Properties

Empty

Represents a new empty instance of the NeutralText.

public static NeutralText Empty { get; }

Property Value

NeutralText

An empty NeutralText object.

See Also

IsBalanced

Indicates whether the current neutral text value has balanced brackets and parentheses.

public bool IsBalanced { get; }

Property Value

bool

true if the text has balanced brackets and parentheses; otherwise, false.

See Also

IsEmpty

Indicates whether the current neutral text value is an empty string.

public bool IsEmpty { get; }

Property Value

bool

true if the text empty; otherwise false.

See Also

IsSingle

Indicates whether the current neutral text value is a single instruction, as opposed to a rung/line of multiple instructions.

public bool IsSingle { get; }

Property Value

bool

true if the text represents a single instruction. false if not, meaning the text is a collection of multiple instruction patterns.

See Also

Methods

ContainsKey(string)

Returns a value indicating whether a specified instruction key occurs within this neutral text.

public bool ContainsKey(string instructionKey)

Parameters

instructionKey string

The instruction name to seek.

Returns

bool

true if this text contains the instruction key; otherwise, false..

See Also

ContainsSignature(Instruction)

Returns a value indicating whether a specified instruction signature occurs within this neutral text.

public bool ContainsSignature(Instruction instruction)

Parameters

instruction Instruction

The instruction for which to seek.

Returns

bool

true if this text contains the signature pattern defined by instruction.

See Also

ContainsTag(TagName, IEqualityComparer<TagName>?)

Returns a value indication whether a specified tag name occurs within this neutral text.

public bool ContainsTag(TagName tagName, IEqualityComparer<TagName>? comparer = null)

Parameters

tagName TagName

The tag name to seek.

comparer IEqualityComparer<TagName>

The optional equality comparer to user for evaluating tag equivalence.

Returns

bool

true if tagName is contained withing the text and passes the equality check specified by comparer.

See Also

ContainsText(NeutralText)

Returns a value indicating whether a specified subtext occurs within this neutral text.

public bool ContainsText(NeutralText text)

Parameters

text NeutralText

The neutral text to seek.

Returns

bool

true if text occurs within this text, or if text is an empty string (""); otherwise, false.

See Also

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

See Also

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

See Also

HasPattern(string)

Runs the provided regex pattern against the neutral text and indicates whether the patterns is matched.

public bool HasPattern(string regex)

Parameters

regex string

The regex pattern to test against.

Returns

bool

true if regex is a match against this neutral text value.

See Also

Instructions()

Returns a collection of Instruction objects that were found in the current neutral text value.

public IEnumerable<Instruction> Instructions()

Returns

IEnumerable<Instruction>

An IEnumerable<T> containing Instruction objects found in the text.

See Also

Keys()

Gets a collection of instruction keys or names that occur in the current neutral text.

public IEnumerable<string> Keys()

Returns

IEnumerable<string>

A IEnumerable<T> containing the names/keys of al found instructions.

See Also

Operands()

Returns a collection of all found operands in the current neutral text value.

public IEnumerable<string> Operands()

Returns

IEnumerable<string>

An IEnumerable<T> containing the instruction(s) operand arguments found in the current text.

Remarks

This will return a flat list of operands for all instructions. If you want to get operands and corresponding instruction key, use the OperandsByKey() methods, which will return found operands along with the corresponding instruction.

See Also

OperandsByKey()

Returns a collection of KeyValuePair with the key being the instruction and corresponding operand arguments as the value.

public IEnumerable<KeyValuePair<string, IEnumerable<string>>> OperandsByKey()

Returns

IEnumerable<KeyValuePair<string, IEnumerable<string>>>

A IEnumerable<T> of KeyValuePair objects containing instruction key and corresponding operands values.

See Also

OperandsByKey(Instruction)

Returns a collection of KeyValuePair with the key being the instruction and corresponding operand arguments as the value.

public IEnumerable<KeyValuePair<Instruction, IEnumerable<string>>> OperandsByKey(Instruction instruction)

Parameters

instruction Instruction

Returns

IEnumerable<KeyValuePair<Instruction, IEnumerable<string>>>

A IEnumerable<T> of KeyValuePair objects containing instruction key and corresponding operands values.

See Also

OperandsByKey(string)

Returns a collection of KeyValuePair with the key being the instruction and corresponding operand arguments as the value.

public IEnumerable<KeyValuePair<string, IEnumerable<string>>> OperandsByKey(string key)

Parameters

key string

Returns

IEnumerable<KeyValuePair<string, IEnumerable<string>>>

A IEnumerable<T> of KeyValuePair objects containing instruction key and corresponding operands values.

See Also

References()

Returns a collection of KeyValuePair<TKey, TValue> with the key being a tag found in the neutral text instance, and the value being it's corresponding instruction sub text where it is referenced within the neutral text instance.

public IEnumerable<KeyValuePair<TagName, NeutralText>> References()

Returns

IEnumerable<KeyValuePair<TagName, NeutralText>>

A IEnumerable<T> of KeyValuePair objects containing TagName and NeutralText pairs.

See Also

Split()

Splits the current neutral text into a collection of sub-texts representing each individual instruction found in the current text value.

public IEnumerable<NeutralText> Split()

Returns

IEnumerable<NeutralText>

An IEnumerable<T> containing the NeutralText objects that represent each individual instruction text.

See Also

SplitBy(Instruction)

Splits the current neutral text into a collection of sub-texts representing a specific single instruction.

public IEnumerable<NeutralText> SplitBy(Instruction instruction)

Parameters

instruction Instruction

Returns

IEnumerable<NeutralText>

An IEnumerable<T> containing the NeutralText objects that represent each individual instruction text.

See Also

SplitBy(IEnumerable<Instruction>)

Splits the current neutral text into a collection of sub-texts representing a set of specific instructions.

public IEnumerable<NeutralText> SplitBy(IEnumerable<Instruction> instructions)

Parameters

instructions IEnumerable<Instruction>

Returns

IEnumerable<NeutralText>

An IEnumerable<T> containing the NeutralText objects that represent each individual instruction text.

See Also

SplitBy(IEnumerable<string>)

Splits the current neutral text into a collection of sub-texts matching a set of regex patterns.

public IEnumerable<NeutralText> SplitBy(IEnumerable<string> patterns)

Parameters

patterns IEnumerable<string>

A collection of regular expressions for which to match against.

Returns

IEnumerable<NeutralText>

An IEnumerable<T> containing the NeutralText objects that match the specified patterns.

See Also

SplitBy(string)

Splits the current neutral text into a collection of sub-texts matching a specific regex pattern.

public IEnumerable<NeutralText> SplitBy(string pattern)

Parameters

pattern string

The regular expression for which to match against.

Returns

IEnumerable<NeutralText>

An IEnumerable<T> containing the NeutralText objects that match the specified pattern.

See Also

SplitByKey(string)

Splits the current neutral text into a collection of sub-texts having a specific instruction key.

public IEnumerable<NeutralText> SplitByKey(string key)

Parameters

key string

The instruction key to match against.

Returns

IEnumerable<NeutralText>

An IEnumerable<T> containing the NeutralText objects that represent each individual instruction text.

See Also

SplitByKeys(IEnumerable<string>)

Splits the current neutral text into a collection of sub-texts having a set of instruction keys.

public IEnumerable<NeutralText> SplitByKeys(IEnumerable<string> keys)

Parameters

keys IEnumerable<string>

A collection of instruction keys to match against.

Returns

IEnumerable<NeutralText>

An IEnumerable<T> containing the NeutralText objects that represent each individual instruction text.

See Also

Tags()

Gets a collection of tag names found in the current neutral text.

public IEnumerable<TagName> Tags()

Returns

IEnumerable<TagName>

A IEnumerable<T> of TagName values that were in from the current text.

See Also

TagsIn(Instruction)

Gets a collection of tag names found in the current neutral text that are operands or arguments to a specific instruction.

public IEnumerable<TagName> TagsIn(Instruction instruction)

Parameters

instruction Instruction

The instruction for which to find tags as arguments to.

Returns

IEnumerable<TagName>

A IEnumerable<T> containing tag names found in the specified instruction.

See Also

TagsIn(string)

Gets all tags found in the current neutral text that are arguments to a specific instruction key value.

public IEnumerable<TagName> TagsIn(string key)

Parameters

key string

The name of the instruction for which to get tags.

Returns

IEnumerable<TagName>

A IEnumerable<T> containing tag names found in the specified instruction.

See Also

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

See Also

Operators

operator ==(NeutralText?, NeutralText?)

Determines if the provided objects are equal.

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

Parameters

left NeutralText

An object to compare.

right NeutralText

An object to compare.

Returns

bool

true if the provided objects are equal; otherwise, false.

See Also

implicit operator string(NeutralText)

Converts a NeutralText object to a string object.

public static implicit operator string(NeutralText text)

Parameters

text NeutralText

the NeutralText instance to convert.

Returns

string

A string that represents the value of the NeutralText.

See Also

implicit operator NeutralText(string)

Converts a string object to a NeutralText object.

public static implicit operator NeutralText(string text)

Parameters

text string

the string instance to convert.

Returns

NeutralText

A NeutralText that represents the value of the string.

See Also

operator !=(NeutralText?, NeutralText?)

Determines if the provided objects are not equal.

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

Parameters

left NeutralText

An object to compare.

right NeutralText

An object to compare.

Returns

bool

true if the provided objects are not equal; otherwise, false.

See Also

See Also