Class Dimensions
Represents the dimensions of an array for a Logix type.
public sealed class Dimensions : IEquatable<Dimensions>
- Inheritance
-
Dimensions
- Implements
- Inherited Members
Remarks
Logix Dimensions
can have one, two, or three dimensions.
These dimensions are represented by the properties X, Y, and Z.
This class also provides helpful methods and properties for working with dimensions of an array.
Constructors
Dimensions(ushort)
Creates a one dimensional instance with the provided values.
public Dimensions(ushort x)
Parameters
x
ushortThe length of the first dimensional element
Dimensions(ushort, ushort)
Creates a two dimensional instance with the provided values.
public Dimensions(ushort x, ushort y)
Parameters
x
ushortThe length of the first dimensional element
y
ushortThe length of the second dimensional element
Exceptions
- ArgumentException
Thrown in the value of
x
is 0 andy
is greater than 0.
Dimensions(ushort, ushort, ushort)
Creates a three dimensional instance with the provided values.
public Dimensions(ushort x, ushort y, ushort z)
Parameters
x
ushortThe length of the first dimensional element
y
ushortThe length of the second dimensional element
z
ushortThe length of the third dimensional element
Exceptions
- ArgumentException
Thrown in the value of
y
is 0 andz
is greater than 0.
Properties
Empty
Represents an empty Dimensions object, or object with all three dimensional parameters equal to zero.
public static Dimensions Empty { get; }
Property Value
IsEmpty
Indicates whether Dimensions are empty or Length equals zero.
public bool IsEmpty { get; }
Property Value
IsMultiDimensional
Indicates whether Dimensions are multi-dimensional.
public bool IsMultiDimensional { get; }
Property Value
Remarks
Multi-dimensional simply means that the dimensions have a value for Y or Z.
Length
Gets the value of the total length of Dimensions.
public int Length { get; }
Property Value
- int
An integer that represents the combined length of all three dimensional parameters.
Rank
Gets the value for the number or parameters or coordinates in the Dimensions object.
public int Rank { get; }
Property Value
- int
An integer value 1, 2, or 3 that represents the number of dimensional parameters for the current object.
Remarks
More plainly, this property indicates whether the current Dimensions are one, two, or three dimensional based on the values of X, Y, and Z.
X
Gets the value of the X (or first) dimensional unit of the Dimensions object.
public ushort X { get; }
Property Value
- ushort
An unsigned short that represents the length the first dimensional parameter.
Y
Gets the value of the Y or second dimensional unit of the Dimensions object.
public ushort Y { get; }
Property Value
- ushort
An unsigned short that represents the length the second dimensional parameter.
Z
Gets the value of the Z or third dimensional unit of the Dimensions object.
public ushort Z { get; }
Property Value
- ushort
An unsigned short that represents the length the third dimensional parameter.
Methods
Copy()
Creates a new instance of the current Dimensions with the same value.
public Dimensions Copy()
Returns
- Dimensions
A new Dimensions object with the same value.
Equals(Dimensions?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Dimensions? other)
Parameters
other
DimensionsAn object to compare with this object.
Returns
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
FromArray(Array)
Returns the dimension of a specified array type.
public static Dimensions FromArray(Array array)
Parameters
array
ArrayThe array instance for which to determine the dimensions.
Returns
Exceptions
- ArgumentNullException
array
is null.- ArgumentOutOfRangeException
array
has a dimensional rank that is greater than ushort max value -or-array
has more than three dimensions.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Indices()
Gets the set of indices for the Dimensions object.
public IEnumerable<string> Indices()
Returns
- IEnumerable<string>
An IEnumerable<T> containing all index strings that represent the indices of a dimension array. If Dimensions are empty, then an empty collection.
Remarks
The indices are determined by the dimensions (x, y, z) of the object.
Parse(string)
Parses the provided string to a Dimensions object.
public static Dimensions Parse(string value)
Parameters
value
stringThe value to parse.
Returns
- Dimensions
A new Dimensions object that represents parsed dimensional value. If value empty or 0; returns Empty.
Examples
1 2 3 -or- [1,2]
Remarks
Valid dimensions must have only numbers and special characters "[ ,]". If more than 3 numbers are found in the provided value, or the numbers are not parsable to a ushort, then exception will be thrown.
Exceptions
- ArgumentNullException
value is null
- ArgumentException
value contains invalid characters.
- See Also
ToIndex()
Generates a string value that represents the Dimensions in the array bracket notation.
public string ToIndex()
Returns
- string
A string of numbers separated by a comma and enclosed in brackets.
Examples
[1,2,3]
ToString()
Generates a string value that represents the Dimensions in the L5X format.
public override string ToString()
Returns
- string
A string of numbers separated by a single space.
Examples
1 2 3
TryParse(string, out Dimensions?)
Attempts to parse the provided string to a Dimensions object.
public static bool TryParse(string value, out Dimensions? dimensions)
Parameters
value
stringThe value to parse.
dimensions
DimensionsWhen the method returns, the value of the parsed dimensions if successful; otherwise, null
Returns
- bool
true if the parse was successful; otherwise, false.
Examples
1 2 3 -or- [1,2,3]
Remarks
Valid dimensions must have only numbers and special characters "[ ,]". If more than 3 numbers are found in the provided value, or the numbers are not parsable to a ushort, then exception will be thrown.
Exceptions
- ArgumentNullException
value is null
- See Also
Operators
operator ==(Dimensions, Dimensions)
Determines whether the objects are equal.
public static bool operator ==(Dimensions left, Dimensions right)
Parameters
left
DimensionsAn object to compare.
right
DimensionsAn object to compare.
Returns
- bool
true if the objects are equal, otherwise, false.
implicit operator int(Dimensions)
Converts the provided Dimensions to a int value.
public static implicit operator int(Dimensions dimensions)
Parameters
dimensions
DimensionsThe Dimensions value to convert.
Returns
implicit operator Dimensions(ushort)
Converts the provided ushort to a Dimensions value.
public static implicit operator Dimensions(ushort length)
Parameters
length
ushortThe length value to convert.
Returns
- Dimensions
A Dimensions value representing the provided ushort length.
operator !=(Dimensions, Dimensions)
Determines whether the objects are not equal.
public static bool operator !=(Dimensions left, Dimensions right)
Parameters
left
DimensionsAn object to compare.
right
DimensionsAn object to compare.
Returns
- bool
true if the objects are not equal, otherwise, false.