Class TagName
A string wrapper representing a Logix TagName
.
public sealed class TagName : IComparable<TagName>, IEquatable<TagName>
- Inheritance
-
TagName
- Implements
- Inherited Members
Remarks
This value type class make working with string tag name easier by providing methods fo analyzing and breaking the tag name into constituent parts (members).
Constructors
TagName(string)
Creates a new TagName object with the provided string tag name.
public TagName(string tagName)
Parameters
tagName
stringThe string that represents the tag name value.
Exceptions
- ArgumentNullException
tagName is null.
Properties
Depth
A zero-based number representing the depth of the tag name value. In other words, the number of members between this tag name and the root.
public int Depth { get; }
Property Value
Remarks
This value represents the number of members between the root tag and last member name (i.e. one less than the number of members in the tag name). This is helpful for filtering tag descendents. Note that array indices are also considered a member. For example, 'MyTag[1].Value' has a depth of 2 since '[1]' and 'Value' are descendent member names of the root tag 'MyTag' member.
Empty
Gets the static empty TagName value.
public static TagName Empty { get; }
Property Value
IsEmpty
Gets a value indicating whether the current TagName value is empty.
public bool IsEmpty { get; }
Property Value
IsQualified
Gets a value indicating whether the current TagName is a valid representation of a tag name.
public bool IsQualified { get; }
Property Value
Member
Gets the member name, or the last member of Members, of the tag name value.
public string Member { get; }
Property Value
Remarks
The Member
of a tag name represents the last member name of the string. This is the string after the final
member separator character.
Members
Returns a collection of string names representing each individual member of the full tag name value.
public IEnumerable<string> Members { get; }
Property Value
Remarks
Each member of a tag name can be represented by a string, array bracket, or bit index value. For example, MyTag[1].MemberName.5 has 4 members.
Operand
Gets the operand portion of the TagName value.
public string Operand { get; }
Property Value
Remarks
The Operand
of a tag name represents the part of the name after Root. This value will always be
the full tag name value without the leading root name. The operand will include the leading '.' character.
- See Also
Path
Gets the member path of the tag name value.
public string Path { get; }
Property Value
Remarks
The Path
of a tag name represents a name relative to Root. The value will always be the full tag name
without the leading root name. This is similar to Operand, except that is also removes any
leading member separator character ('.').
- See Also
Root
Gets the tag or root portion of the TagName string.
public string Root { get; }
Property Value
Remarks
The root portion of a given tag name is simply the beginning part of the tag name up to the first member separator character ('.' or '['). For Module defined tags, this includes the colon separator.
This value can be swapped out easily using Rename(string) to return a new TagName with the newly specified root tag name value.
- See Also
Methods
Combine(IEnumerable<string>)
Combines a collection of member names into a single TagName value.
public static TagName Combine(IEnumerable<string> members)
Parameters
members
IEnumerable<string>The collection of strings that represent the member names of the tag name value.
Returns
Exceptions
- ArgumentException
If a provided name does not match the member pattern format.
Combine(params string[])
Combines a series of strings into a single TagName value, inserting member separator characters as needed.
public static TagName Combine(params string[] members)
Parameters
members
string[]The series of strings that, in order, comprise the full tag name value.
Returns
Exceptions
- ArgumentException
If any provided member does not match the member pattern format.
CompareTo(TagName?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(TagName? other)
Parameters
other
TagNameAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
ValueMeaning
Less than zero
This instance precedes
other
in the sort order.Zero
This instance occurs in the same position in the sort order as
other
.Greater than zero
This instance follows
other
in the sort order.
Concat(string, string)
Concatenates two strings to produce a new TagName value. This method will also insert the '.'
member separator character if not found at the beginning of right
.
public static TagName Concat(string left, string right)
Parameters
left
stringThe first or left side of the tag name to concatenate.
right
stringThe second or right side of the tag name to concatenate.
Returns
Remarks
This method would be more performant than Combine(params string[]), assuming there are just two strings to join together, as it does not iterate a collection and build a string with a string builder class. This method simply joins to strings using a string format syntax.
Contains(TagName)
Determines if the provided tagName is contained within the current value.
public bool Contains(TagName tagName)
Parameters
tagName
TagNameThe tag name to evaluate as a sub path or contained tag name path.
Returns
- bool
true if tagName is contained within the current value; otherwise, false.
Exceptions
- ArgumentNullException
tagName is null.
Equals(TagName?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(TagName? other)
Parameters
other
TagNameAn object to compare with this object.
Returns
Equals(TagName, TagName, IEqualityComparer<TagName>)
Determines whether the specified TagName objects are equal using the specified IEqualityComparer<T>.
public static bool Equals(TagName first, TagName second, IEqualityComparer<TagName> comparer)
Parameters
first
TagNameA tag name object to compare.
second
TagNameA tag name object to compare.
comparer
IEqualityComparer<TagName>The equality comparer to use for comparison.
Returns
- bool
true
if the tag name are equal according too the provided comparer; otherwise, false.
Remarks
Use the prebuilt TagNameComparer class for several predefined comparers.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Rename(string)
Returns a new tag name with the root Root value replaced with the provided string tag.
public TagName Rename(string tag)
Parameters
tag
stringThe new root tag name value to replace.
Returns
Remarks
Note that this doesn't change the current tag name value, rather, returns a new object with the changed value. This ensures the immutability of TagName.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
Operators
operator ==(TagName?, TagName?)
Determines if the provided objects are equal.
public static bool operator ==(TagName? left, TagName? right)
Parameters
Returns
- bool
true if the provided objects are equal; otherwise, false.
implicit operator string(TagName)
public static implicit operator string(TagName tagName)
Parameters
Returns
implicit operator TagName(string)
public static implicit operator TagName(string tagName)
Parameters
Returns
operator !=(TagName?, TagName?)
Determines if the provided objects are not equal.
public static bool operator !=(TagName? left, TagName? right)
Parameters
Returns
- bool
true if the provided objects are not equal; otherwise, false.