private static Func <IClientProxy, T> GenerateClientBuilder() { TypedClientBuilder <T> .VerifyInterface(typeof(T)); Type clientType = TypedClientBuilder <T> .GenerateInterfaceImplementation(AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Microsoft.AspNetCore.SignalR.TypedClientBuilder"), AssemblyBuilderAccess.Run).DefineDynamicModule("Microsoft.AspNetCore.SignalR.TypedClientBuilder")); return((Func <IClientProxy, T>)(proxy => (T)Activator.CreateInstance(clientType, (object)proxy))); }
private static void VerifyInterface(Type interfaceType) { if (!interfaceType.IsInterface) { throw new InvalidOperationException("Type must be an interface."); } if (interfaceType.GetProperties().Length != 0) { throw new InvalidOperationException("Type must not contain properties."); } if (interfaceType.GetEvents().Length != 0) { throw new InvalidOperationException("Type must not contain events."); } foreach (MethodInfo method in interfaceType.GetMethods()) { TypedClientBuilder <T> .VerifyMethod(interfaceType, method); } foreach (Type interfaceType1 in interfaceType.GetInterfaces()) { TypedClientBuilder <T> .VerifyInterface(interfaceType1); } }