public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { if (MessageInspectors is object) { PropertyInfo propertyInfo = clientRuntime.GetType().GetTypeInfo().GetDeclaredProperty("MessageInspectors"); foreach (IClientMessageInspector MessageInspector in MessageInspectors) { (propertyInfo.GetValue(clientRuntime) as ICollection <IClientMessageInspector>).Add(MessageInspector); } } }
/// <summary> /// Add <see langword="this"/> to the message inspectors for the channel /// </summary> /// <param name="endpoint">The <see cref="ServiceEndpoint"/></param> /// <param name="clientRuntime">The <see cref="ClientRuntime"/></param> public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { var t = Type.GetType("Mono.Runtime"); ICollection <IClientMessageInspector> inspectors; if (t != null) { var prop = clientRuntime.GetType() .GetTypeInfo() .GetDeclaredProperty("MessageInspectors"); inspectors = (ICollection <IClientMessageInspector>)prop .GetValue(clientRuntime); } else { inspectors = clientRuntime.ClientMessageInspectors; } inspectors.Add(this); }