DomainType.FromUnsafe #1448
Replies: 1 comment
-
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.
-
Hello there!
I'm trying v5 of LanguageExt. There is a new way to define domain types — trait
DomainType
2. There is a static virtual method
FromUnsafe` in this interface with default implementation. But I don't quite undersand how to use it.In my head
Shmoogl
member initialization should work "out of the box", but I get a compler error shown in the comment. Why so? Am I missing something? Must admit, that statics and/or virtuals in interfaces are somethings I'm not very familiar.Beta Was this translation helpful? Give feedback.
All reactions