DomainType.FromUnsafe #1448
-
|
Hello there! I'm trying v5 of LanguageExt. There is a new way to define domain types — trait internal sealed class Hostname(string value) : DomainType<Hostname, string>
{
// Imagine there is actually a proper hostname validation
public static Fin<Hostname> From(string repr) => new Hostname(repr);
public string To() => value;
}
internal static class Hostnames
{
// CS0117 'Hostname' does not contain a definition for 'FromUnsafe'
public static readonly Hostname Shmoogl = Hostname.FromUnsafe("shmoogle.com");
}In my head |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Unfortunately, the C# language team, in their infinite wisdom, crippled the static-method interface system in the name of "backwards compatibility". There were some minor edge-cases where adding a static method after-the-fact to an interface might change the behaviour of the derived types that never saw that method before. So, instead of just accepting this edge-case and informing programmers to watch out for this issue and have a 1 time fix-up for the edge-cases... they instead compromised all future code written with this feature. Thanks Microsoft. The crux of it is this: You cannot directly invoke a default static method. i.e.public interface Base
{
static virtual int Foo() =>
100;
}
// ERROR: A static virtual or abstract interface member can be accessed only on a type parameter
var x = Base.Foo(); If you create a type that derived from the
|
Beta Was this translation helpful? Give feedback.
Unfortunately, the C# language team, in their infinite wisdom, crippled the static-method interface system in the name of "backwards compatibility". There were some minor edge-cases where adding a static method after-the-fact to an interface might change the behaviour of the derived types that never saw that method before.
So, instead of just accepting this edge-case and informing programmers to watch out for this issue and have a 1 time fix-up for the edge-cases... they instead compromised all future code written with this feature. Thanks Microsoft.
The crux of it is this:
You cannot directly invoke a default static method. i.e.