Public parameterless constructor required in order to use generic ValueOf<TValue, TThis>
I think the requirement of a parameterless constructor should be fixed in order to avoid the creation of invalid objects which is an antipattern regarding DDD
Do you mean there should be a parameterless instance constructor?
Currently the only parameterless constructor is a private static. This is run once per type TThis and is required to construct the factory method for creating instances using ValueOf<TThis>.From(TValue).
I think he means the problem that the library does not prohibit this:
public class Email : ValueOf<string, Email>
{
}
var email = new Email();
So later on, when you start using the type, you will get some NullReference exceptions.
I am not sure if the expectation of everyone playing nice and using the factory method is a good one.
Having a mandatory constructor of T instead would make the wrting of the classes a little bit more ugly, but would get rid of this problem.
I had a very similar library to this one, with the major difference being that validation wasn't optional as it was required in the constructor, e.g.
public class Age : ValueObject<int>
{
public Age(int value) : base(value, x => x < 0 : "negative age" : string.Empty) { }
}
The base class would call the provided delegate and throw if it returned anything other than an empty string.
The down side is two heap allocations, one for the instance itself, and one for the delegate.