How to solve “Must be MarshalByRefObject” in a good but multiple-inheritance amputated language like C#?

前端 未结 5 577
我在风中等你
我在风中等你 2020-12-18 19:55

How to solve \"Must be MarshalByRefObject\" in a good but multiple-inheritance amputated language like C#?

The problem is very simple, in several cases you just have

5条回答
  •  时光说笑
    2020-12-18 20:00

    I had success with a generic approach. T doesn't have to be "MarshalByRefObject". Of course you'll have to replace "RemoteProcess" with the object you use for remoting. Then you can access your non-MarshalByRefObject as RemotingHost.RemoteObject.

    public class RemotingHost : MarshalByRefObject where T: class
    {
        RemoteProcess host;
        T remoteObject;
        public T RemoteObject { get { return remoteObject; } }
    
        public RemotingAdmin()
        {
            host = new RemoteProcess();
            remoteObject = (T)host.CreateObject(typeof(T));
        }
    }
    

提交回复
热议问题