You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And this is how it could look like with StringComparison.OrdinalIgnoreCase. Note the changes in Equals(OrderId other), CompareTo(OrderId other) and GetHashCode(). The null checks are not needed when using string.Equals and string.Compare.
readonlypartialstructOrderId: System.IComparable<OrderId>, System.IEquatable<OrderId>{publicstringValue{get;}publicOrderId(stringvalue){Value=value??thrownew System.ArgumentNullException(nameof(value));}publicstaticreadonlyOrderIdEmpty=new OrderId(string.Empty);publicboolEquals(OrderIdother){returnstring.Equals(Value, other.Value, StringComparison.OrdinalIgnoreCase);}publicoverrideboolEquals(objectobj){if(ReferenceEquals(null, obj))returnfalse;return obj is OrderId other && Equals(other);}publicoverrideintGetHashCode()=> Value.GetHashCode();publicoverridestringToString()=> Value;publicstaticbooloperator==(OrderIda,OrderIdb)=> a.Equals(b);publicstaticbooloperator!=(OrderIda,OrderIdb)=>!(a==b);publicintCompareTo(OrderIdother){returnstring.Compare(Value, other.Value, StringComparison.OrdinalIgnoreCase);}}
The StronglyTypedIdAttribute would need a new option to specify the StringComparison and possibly also StronglyTypedIdDefaultsAttribute.
The text was updated successfully, but these errors were encountered:
This is a great point. In #117 I've changed to use StringComparison.Ordinal instead of the current culture. Additionally, that PR allows complete customisation of the IDs, so you can create a custom template for this behaviour 🙂
String comparison can be
Please see https://learn.microsoft.com/en-us/dotnet/api/system.stringcomparison for more details.
It would be a great enhancement to StronglyTypedId if one could specify which one to use.
This is the source generated for a string (for the latest version of StronglyTypedId).
And this is how it could look like with
StringComparison.OrdinalIgnoreCase
. Note the changes inEquals(OrderId other)
,CompareTo(OrderId other)
andGetHashCode()
. The null checks are not needed when usingstring.Equals
andstring.Compare
.The
StronglyTypedIdAttribute
would need a new option to specify theStringComparison
and possibly alsoStronglyTypedIdDefaultsAttribute
.The text was updated successfully, but these errors were encountered: