IValueOf with static abstract From(TValue) at the cost of compatibility
Perhaps a change for later when there's greater compatibility, but having the static From function in an interface is amazing! (and just what I needed)
What's an example of usage?
Allowing a class (StringExpectation) that is derrived from ValueOf to call the static .From on a class (GreetingMessage) that in turn derrives from itself. ValueOf => StringExpectation => GreetingMessage
Simplified example:
public class StringExpectation<TSelf> : ValueOf<string, TSelf> where TSelf : StringExpectation<TSelf>, IValueOf<string, TSelf>
{
public static TSelf From(JToken token) =>
//Do a bunch of validation with the token, and finally:
TSelf.From(token.ToString());
}
public class GreetingMessage : StringExpectation<GreetingMessage> { }
The compiler does not understand that TSelf.From(string) exists alone from TSelf : StringExpectation<TSelf>, or even from TSelf : ValueOf<string, TSelf>
Implementing IValueOf<TValue, TThis> with static abstract From(TValue) allows such behaviour.