是否有可能实现在C#中混入? [英] Is it possible to implement mixins in C#?

查看:150
本文介绍了是否有可能实现在C#中混入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说它可能带扩展方法,但我不能完全弄清楚自己。我想看看是否有可能一个具体的例子。

I've heard that it's possible with extension methods, but I can't quite figure it out myself. I'd like to see a specific example if possible.

谢谢!

推荐答案

这真的取决于你的意思是混入是什么 - 大家似乎有一个稍微不同的想法。那种混入的我的的看到(但不是在C#中可用)正在实现通成分简单的:

It really depends on what you mean by "mixin" - everyone seems to have a slightly different idea. The kind of mixin I'd like to see (but which isn't available in C#) is making implementation-through-composition simple:

public class Mixin : ISomeInterface
{
    private SomeImplementation impl implements ISomeInterface;

    public void OneMethod()
    {
        // Specialise just this method
    }
}

,编译器将实现ISomeInterface只是进行代理每一个成员,除非是班上另一个实现implement执行直接。

The compiler would implement ISomeInterface just by proxying every member to "impl" unless there was another implementation in the class directly.

这一切都不是可能的此刻虽然:)

None of this is possible at the moment though :)

这篇关于是否有可能实现在C#中混入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆