/// <inheritdoc /> public override object CreateProxy(Type mockType, Moq.IInterceptor interceptor, Type[] interfaces, object[] arguments) { // All generated proxies need to implement `IProxy`: var additionalInterfaces = new Type[1 + interfaces.Length]; additionalInterfaces[0] = typeof(IProxy); Array.Copy(interfaces, 0, additionalInterfaces, 1, interfaces.Length); if (mockType.IsInterface) { // While `CreateClassProxy` could also be used for interface types, // `CreateInterfaceProxyWithoutTarget` is much faster (about twice as fast): return(generator.CreateInterfaceProxyWithoutTarget(mockType, additionalInterfaces, this.generationOptions, new Interceptor(interceptor))); } else if (mockType.IsDelegateType()) { var options = new ProxyGenerationOptions(); options.AddDelegateTypeMixin(mockType); var container = generator.CreateClassProxy(typeof(object), additionalInterfaces, options, new Interceptor(interceptor)); return(Delegate.CreateDelegate(mockType, container, container.GetType().GetMethod("Invoke"))); } try { return(generator.CreateClassProxy(mockType, additionalInterfaces, this.generationOptions, arguments, new Interceptor(interceptor))); } catch (TypeLoadException e) { throw new ArgumentException(Resources.TypeNotMockable, e); } catch (MissingMethodException e) { throw new ArgumentException(Resources.ConstructorNotFound, e); } }
/// <inheritdoc /> public override object CreateProxy(Type mockType, Moq.IInterceptor interceptor, Type[] interfaces, object[] arguments) { // All generated proxies need to implement `IProxy`: var additionalInterfaces = new Type[1 + interfaces.Length]; additionalInterfaces[0] = typeof(IProxy); Array.Copy(interfaces, 0, additionalInterfaces, 1, interfaces.Length); if (mockType.IsInterface) { // While `CreateClassProxy` could also be used for interface types, // `CreateInterfaceProxyWithoutTarget` is much faster (about twice as fast): return(generator.CreateInterfaceProxyWithoutTarget(mockType, additionalInterfaces, this.generationOptions, new Interceptor(interceptor))); } try { return(generator.CreateClassProxy(mockType, additionalInterfaces, this.generationOptions, arguments, new Interceptor(interceptor))); } catch (TypeLoadException e) { throw new ArgumentException(Resources.InvalidMockClass, e); } catch (MissingMethodException e) { throw new ArgumentException(Resources.ConstructorNotFound, e); } }
/// <inheritdoc /> public override object CreateProxy(Type mockType, Moq.IInterceptor interceptor, Type[] interfaces, object[] arguments) { if (mockType.GetTypeInfo().IsInterface) { // While `CreateClassProxy` could also be used for interface types, // `CreateInterfaceProxyWithoutTarget` is much faster (about twice as fast): return(generator.CreateInterfaceProxyWithoutTarget(mockType, interfaces, this.generationOptions, new Interceptor(interceptor))); } try { return(generator.CreateClassProxy(mockType, interfaces, this.generationOptions, arguments, new Interceptor(interceptor))); } catch (TypeLoadException e) { throw new ArgumentException(Resources.InvalidMockClass, e); } catch (MissingMethodException e) { throw new ArgumentException(Resources.ConstructorNotFound, e); } }
internal Interceptor(Moq.IInterceptor interceptor) { this.interceptor = interceptor; }
internal Interceptor(Moq.IInterceptor underlying) { this.underlying = underlying; }