TUX002 - Do not assign new to a refined type
A refined type must always be constructed via its Parse or TryParse
static methods.
Creating it via its default empty constructor will result in an invalid refined type and will throw on access to any of its underlying values.
using Tuxedo;
public readonly partial struct TrueBool
{
[Refinement("Must be 'true'", Name = nameof(TrueBool))]
public static bool Refinement(bool value) => value;
}
public class Test
{
public void TestMethod()
{
// these are not compliant
TrueBool tb1 = new();
var tb2 = new TrueBool();
// these are
var tb3 = (TrueBool)true;
var tb4 = TrueBool.Parse(true);
if(TrueBool.TryParse(true, out TrueBool tb5, out _))
{
/// tb5 can be used here
}
}
}