Class NeutralText
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
textstringA 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
trueif 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
trueif the text empty; otherwisefalse.
- 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
trueif the text represents a single instruction.falseif 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
instructionKeystringThe instruction name to seek.
Returns
- bool
trueif 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
instructionInstructionThe instruction for which to seek.
Returns
- bool
trueif this text contains the signature pattern defined byinstruction.
- 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
tagNameTagNameThe tag name to seek.
comparerIEqualityComparer<TagName>The optional equality comparer to user for evaluating tag equivalence.
Returns
- bool
trueiftagNameis contained withing the text and passes the equality check specified bycomparer.
- See Also
ContainsText(NeutralText)
Returns a value indicating whether a specified subtext occurs within this neutral text.
public bool ContainsText(NeutralText text)
Parameters
textNeutralTextThe neutral text to seek.
Returns
- bool
trueiftextoccurs 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
objobjectThe object to compare with the current object.
Returns
- 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
regexstringThe regex pattern to test against.
Returns
- bool
trueifregexis 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
instructionInstruction
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
keystring
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
instructionInstruction
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
instructionsIEnumerable<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
patternsIEnumerable<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
patternstringThe 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
keystringThe 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
keysIEnumerable<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
instructionInstructionThe 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
keystringThe 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
leftNeutralTextAn object to compare.
rightNeutralTextAn 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
textNeutralTextthe
NeutralTextinstance to convert.
Returns
- string
A
stringthat represents the value of theNeutralText.
- See Also
implicit operator NeutralText(string)
Converts a string object to a NeutralText object.
public static implicit operator NeutralText(string text)
Parameters
textstringthe
stringinstance to convert.
Returns
- NeutralText
A
NeutralTextthat represents the value of thestring.
- See Also
operator !=(NeutralText?, NeutralText?)
Determines if the provided objects are not equal.
public static bool operator !=(NeutralText? left, NeutralText? right)
Parameters
leftNeutralTextAn object to compare.
rightNeutralTextAn object to compare.
Returns
- bool
true if the provided objects are not equal; otherwise, false.
- See Also