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
It should not be possible to construct a message class that is not valid; however, all message types currently have public setters. Some classes have a "validate" method, but this is too easy to forget about.
The text was updated successfully, but these errors were encountered:
Having looked at this in some more detail, I think using records is a good idea but we'll still likely need to add some sort of Validate method as part of the interface that is checked before messages are sent/received. I had hoped that we would be able to implement validation using the type system e.g.,
// https://www.youtube.com/watch?v=KFx9XHpoYV4publicreadonlyrecordstructNonEmptyTrimmedString(stringValue){publicrequiredstringValue{get;init;}=!string.IsNullOrWhiteSpace(Value)?Value.Trim():thrownewArgumentException("Value cannot be null or whitespace",nameof(Value));publicNonEmptyTrimmedString():this(string.Empty){}// Throwspublicstaticimplicitoperatorstring(NonEmptyTrimmedStringvalue)=>value.Value;}
However, it's always possible to zero-initialize a struct so the above doesn't actually provide a guarantee that the validation code is executed. Maybe this would work as a class instead of a struct, but then you lose the value-type semantics.
In any case, these changes should wait until we've implemented the CTP C# wrapper so that we are free to tweak the message classes and not have to worry about mirroring it in Java.
It should not be possible to construct a message class that is not valid; however, all message types currently have public setters. Some classes have a "validate" method, but this is too easy to forget about.
The text was updated successfully, but these errors were encountered: