Implementation of an attribute for properties with System.Double Type to indicate the level of precision?
marlond18 opened this issue · comments
That's interesting and definitely could be added for floating number types!
Could probably call it PrecisionEquality
Version 2.2.0 now supports the attribute CustomEquality, which can be used to bridge any specific case not built into the library, including comparing doubles.
I will leave this issue open however, because I think this should be implemented at some point.
I was experimenting with an implementation using generics to target any floating point type using generic attributes and generic math with IFloatingPoint<T>
. Though that would be restricted to .NET 7 and newer (with C# 11 compiler).
[GeneratedCode("Generator.Equals", "1.0.0.0")]
[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class PrecisionEqualityAttribute<T> : Attribute
where T : IFloatingPoint<T>
{
public T Precision { get; }
public PrecisionEqualityAttribute(T precision)
{
Precision = precision;
}
}