Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过RealProxy挂接事件_C#_Realproxy - Fatal编程技术网

C# 通过RealProxy挂接事件

C# 通过RealProxy挂接事件,c#,realproxy,C#,Realproxy,在这种情况下,我试图钩住事件操作,但无法毫无例外地从代理返回。这里的想法是:我有事件的接口,它们不是在客户端订阅的。所以,当我尝试在客户端引发事件时,我在代理中捕获该事件,并将该事件的名称及其参数发送到远程服务器,我只想从代理返回。这是我的样品 public interface IMyEvents { Action OnPing { get; set; } } public class Proxy : RealProxy { Type type; public Pro

在这种情况下,我试图钩住事件操作,但无法毫无例外地从代理返回。这里的想法是:我有事件的接口,它们不是在客户端订阅的。所以,当我尝试在客户端引发事件时,我在代理中捕获该事件,并将该事件的名称及其参数发送到远程服务器,我只想从代理返回。这是我的样品

public interface IMyEvents
{
    Action OnPing { get; set; }
}

public class Proxy : RealProxy
{
    Type type;

    public Proxy(Type type)
        : base(type)
    {
        this.type = type;
    }

    public override IMessage Invoke(IMessage msg)
    {
        var call = (IMethodCallMessage)msg;
        string MethodName = (string)msg.Properties["__MethodName"];
        object[] parameters = (object[])msg.Properties["__Args"];

        // Send Command to server
        // SendData(MethodName, parameters);

        // tell the invoker that everything's fine
        return new ReturnMessage(null, null, 0, call.LogicalCallContext, call);
    }
}

public class Test
{
    public Test()
    {
        Proxy proxy = new Proxy(typeof(IMyEvents));
        Events = (IMyEvents)proxy.GetTransparentProxy();
    }

    public readonly IMyEvents Events;
}

class Program
{
    public static void Main(string[] args)
    {
        Test t = new Test();
        t.Events.OnPing();  // NullReferenceException
    }
}