I am trying to solve CA2225 , which WARNS on ContrainedValue<T> below, with the following message: Provide a method named 'ToXXX' or 'FromXXX' as an alternate for operator 'ConstrainedValue<T>.implicit operator T(ConstrainedValue<T>)'.
I also inserted PositiveInteger to illustrate a usage example for ConstrainedValue<T> . ConstrainedValue<T> allows derivatives to simply specify the constraint applied to the value type in the constructor. This seems to be a pretty clean way to code this. Is there a way to resolve CA2225 warning, given that I'm dealing with a generic type? How can I provide an alternative operator?
- Perhaps I could implement
ToInt , ToDouble , etc. for all types of values ββand make them throw, if from than one type? But I think it is bad practice for the ToXXX method to choose? - I could create a layer between
ConstrainedValue<T> and PositiveInteger<T> , a ConstrainedInteger . I could put ToInt() in this class. But creating a layer just to satisfy CA2225 seems wrong, and I donβt think the warning will disappear on ConstrainedValue<T> , and I would have to suppress this warning.
code:
namespace OBeautifulCode.AutoFakeItEasy { using System.Diagnostics; using Conditions;
source share