开发者

Can I force a subclass to implement a static parse-method?

开发者 https://www.devze.com 2023-03-28 10:33 出处:网络
I have a class hierarchy where all the implementing classes should have a range of sta开发者_运维技巧tic parse and parse-like methods. Can I somehow \"force\" them to implement these? I know I can\'t

I have a class hierarchy where all the implementing classes should have a range of sta开发者_运维技巧tic parse and parse-like methods. Can I somehow "force" them to implement these? I know I can't use abstract static since that's not allowed. Is there any other way to make sure these methods are implemented?


No, you can't. You wouldn't be able to call them polymorphically anyway.

The best you can easily do is to put unit tests around this functionality.

I've previously suggested static interfaces available purely as a generic type constraint, which could be useful - but it's certainly not part of C# today, and I have no information that there are any plans to implement it :(

0

精彩评论

暂无评论...
验证码 换一张
取 消