Update Optional.cs

- use more efficient empty assignments
- use string interpolation
- adjust method access to minimal needed
This commit is contained in:
BlueBlock
2023-03-21 12:06:38 -04:00
parent 38abc8a167
commit cdc3759c04

View File

@@ -19,7 +19,7 @@ namespace mRemoteNG.Tools
/// </summary>
public Optional()
{
_optional = new T[0];
_optional = Array.Empty<T>();
}
/// <summary>
@@ -30,7 +30,7 @@ namespace mRemoteNG.Tools
{
_optional = value != null
? new[] {value}
: new T[0];
: Array.Empty<T>();
}
public override string ToString()
@@ -97,9 +97,7 @@ namespace mRemoteNG.Tools
if (_optional[0] is IComparable<T>)
return ((IComparable<T>)_optional[0]).CompareTo(other.First());
throw new ArgumentException(string.Format(
"Cannot compare objects. Optional type {0} is not comparable to itself",
typeof(T).FullName));
throw new ArgumentException($"Cannot compare objects. Optional type {typeof(T).FullName} is not comparable to itself");
}
#endregion
@@ -121,7 +119,7 @@ namespace mRemoteNG.Tools
return false;
}
public bool Equals(Optional<T> other)
private bool Equals(Optional<T> other)
{
var otherObj = other.FirstOrDefault();
var thisObj = _optional.FirstOrDefault();