Closed panoukos41 closed 9 months ago
+1 for this but I'd propose an enum
that allows for:
private
constructor (with the implementation otherwise as-is)My idea behind a private constructor would allow for static
factory method(s) to be used for creating instances using a pattern similar to Guid.TryParse
[StronglyTypedId(constructor: StronglyTypedIdConstructor.Private)]
partial struct MyStrongString
{
public static bool TryParse(string value, out MyStrongString? result)
{
if (CanParse) // Pseudo-code
{
result = new MyStrongString(value);
return true;
}
result = null;
return false;
}
}
Sorry for the delay with this 😳. To be honest I got overwhelmed with how to handle the big range of feature requests and options. I think I've found an answer in the big redesign of the library in this PR:
The main idea is to make the library much more maintainable while also giving people a mechanism to customise the generated IDs as much as they like. This will make it easy to make changes like this 🙂
My proposal is to add a boolean switch on the
[StronglyTypedId]
attribute that would indicate if the generator should generate the default constructor that accepts theBackingType
value.That way someone could provide his own custom constructor that accepts the
BackingType
and allow for further customisation of the finalValue
property.I found myself in need of this actually only on the
string
type so far since I wanted to do some extra work to some ids.If this sounds okay with you I would love to sit and try to implement it myself when I have some time 😸