protected void AssignClientSource(object source) { SuperPoolClient client = _client; if (client == null) { #if Matrix_Diagnostics SystemMonitor.Error("Failed to add client source, since client not available (possible Dispose)."); #endif return; } SuperPoolSubscription owner = _owner; if (owner == null) { #if Matrix_Diagnostics SystemMonitor.Error("Failed to add client source, since no owner is available (possible Dispose)."); #endif return; } ReleaseCurrentClientSource(); _clientSource = source; if (_clientSource == null) { #if Matrix_Diagnostics SystemMonitor.OperationWarning("Starting a client with no source attached."); #endif return; } foreach (Type interfaceType in ReflectionHelper.GatherTypeAttributeMarkedInterfaces(source.GetType(), typeof(SuperPoolInterfaceAttribute))) {// Gather all events, from interfaces marked with [SuperPoolInterfaceAttribute]. // Make sure to have created the corresponding proxy instance for this interface type. owner.ProxyTypeManager.ObtainInterfaceProxy(interfaceType); foreach (EventInfo eventInfo in interfaceType.GetEvents()) { Type delegateType = eventInfo.EventHandlerType; GeneratedMethodInfo methodInfo = owner.ProxyTypeManager.Builder.GenerateDynamicMethodProxyDelegate(delegateType); // Create delegate can operate in 2 modes: // - create a static delegate like this (requires instnace upon call): info.Method.CreateDelegate(delegateType); // - create an instance delegate like this (can be direct called): info.Method.CreateDelegate(delegateType, instance); Delegate delegateInstance = methodInfo.StandaloneDynamicMethod.CreateDelegate(delegateType, this); eventInfo.AddEventHandler(source, delegateInstance); EventHandlingInformation subscriptionInfo = new EventHandlingInformation() { DelegateInstance = delegateInstance, EventInfo = eventInfo, GeneratedMethodInfo = methodInfo }; lock (this) { _eventsMethods.Add(methodInfo.Id, subscriptionInfo); } } } }
protected void AssignClientSource(object source) { SuperPoolClient client = _client; if (client == null) { #if Matrix_Diagnostics SystemMonitor.Error("Failed to add client source, since client not available (possible Dispose)."); #endif return; } SuperPoolSubscription owner = _owner; if (owner == null) { #if Matrix_Diagnostics SystemMonitor.Error("Failed to add client source, since no owner is available (possible Dispose)."); #endif return; } ReleaseCurrentClientSource(); _clientSource = source; if (_clientSource == null) { #if Matrix_Diagnostics SystemMonitor.OperationWarning("Starting a client with no source attached."); #endif return; } foreach (Type interfaceType in ReflectionHelper.GatherTypeAttributeMarkedInterfaces(source.GetType(), typeof(SuperPoolInterfaceAttribute))) {// Gather all events, from interfaces marked with [SuperPoolInterfaceAttribute]. // Make sure to have created the corresponding proxy instance for this interface type. owner.ProxyTypeManager.ObtainInterfaceProxy(interfaceType); foreach (EventInfo eventInfo in interfaceType.GetEvents()) { Type delegateType = eventInfo.EventHandlerType; GeneratedMethodInfo methodInfo = owner.ProxyTypeManager.Builder.GenerateDynamicMethodProxyDelegate(delegateType); // Create delegate can operate in 2 modes: // - create a static delegate like this (requires instnace upon call): info.Method.CreateDelegate(delegateType); // - create an instance delegate like this (can be direct called): info.Method.CreateDelegate(delegateType, instance); Delegate delegateInstance = methodInfo.StandaloneDynamicMethod.CreateDelegate(delegateType, this); eventInfo.AddEventHandler(source, delegateInstance); EventHandlingInformation subscriptionInfo = new EventHandlingInformation() { DelegateInstance = delegateInstance, EventInfo = eventInfo, GeneratedMethodInfo = methodInfo }; lock (this) { _eventsMethods.Add(methodInfo.Id, subscriptionInfo); } } } }