Marshall 通过引用从类继承

发布于 2024-11-05 02:21:28 字数 591 浏览 3 评论 0原文

我遇到了多重继承和 MarshallByRefObj 的问题

我遇到的问题是我需要从抽象类继承并且 MarshallByRefObj

抽象类(精简):

public abstract class Drawable : IDrawable
{
    //... Several unimportant methods...
    public IEnumerable<ICard> Shuffle (IEnumerable<ICard>)
    {
        //...shuffle the cards here...
    }
}

我正在尝试创建的类,需要通过通过wcf引用 显然,脱光了……:

public class Deck : Drawable, MarshallByRefObject
{
    //... public stuff that implements a deck to include 
    // search/draw/discard functions...
}

I've got a problem with multiple inheritance and MarshallByRefObj

The problem i have is that I need to inherit from an abstract class AND MarshallByRefObj

The abstract class (stripped down) :

public abstract class Drawable : IDrawable
{
    //... Several unimportant methods...
    public IEnumerable<ICard> Shuffle (IEnumerable<ICard>)
    {
        //...shuffle the cards here...
    }
}

The class I'm trying to make, which needs to be accessed by reference through wcf
Stripped down, obviously...:

public class Deck : Drawable, MarshallByRefObject
{
    //... public stuff that implements a deck to include 
    // search/draw/discard functions...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

打小就很酷 2024-11-12 02:21:28

尝试从 MarshalByRefObject 派生,并实现其他类的接口。然后,定义该类类型的成员,并使您的接口只是对其的代理调用。这很痛苦,但很简单。

public class Deck : MarshalByRefObject, IDrawable
{
    Drawable _drawable = new Drawable(...);

    // Implement IDrawable
    void IDrawable.Foo() { _drawable.Foo(); }
    void IDrawable.Bar() { _drawable.Bar(); }
}

Try deriving from MarshalByRefObject, and implementing the interface of the other class. Then, define a member of that class' type and make your interface just proxy calls to it. It's a pain, but it's straightforward.

public class Deck : MarshalByRefObject, IDrawable
{
    Drawable _drawable = new Drawable(...);

    // Implement IDrawable
    void IDrawable.Foo() { _drawable.Foo(); }
    void IDrawable.Bar() { _drawable.Bar(); }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文