protected object ProtectedCreateClassProxy(Type type, object target, ProxyGeneratorOptions options, IInterceptor[] interceptors) { if (type is null) { throw new ArgumentNullException(nameof(type)); } if (type.IsInterface) { throw new InvalidOperationException($"Unexpected interface for '{type.Name}'"); } if (target != null && !type.IsAssignableFrom(target.GetType())) { throw new InvalidOperationException($"The target '{target.GetType().Name}' is not assignable from '{type.Name}'"); } ProxyTypeDefinition typeDefinition = GetTypeDefinition(type, target, options); return(CreateProxy(typeDefinition, interceptors, target)); }
protected object[] GetArguments(ProxyTypeDefinition typeDefinition, IInterceptor[] interceptors, object target, Type proxyType) { List <object> args = new List <object>(); // interceptors args.Add(interceptors); // target if (target != null) { args.Add(target); } // interceptorSelector ProxyGeneratorOptions options = typeDefinition.Options; IInterceptorSelector interceptorSelector = options?.InterceptorSelector; if (interceptorSelector != null) { args.Add(interceptorSelector); } // mixins if (options != null && options.MixinInstances.Count > 0) { args.AddRange(options.MixinInstances); } // base ctor dependencies ConstructorInfo constructor = proxyType.GetConstructors()[0]; var parameters = constructor.GetParameters(); int length = parameters.Length; if (length > args.Count) { for (int i = args.Count; i < length; i++) { args.Add(ConstructorInjectionResolver.Resolve(parameters[i])); } } return(args.ToArray()); }
public object CreateClassProxyWithTarget(object target, ProxyGeneratorOptions options, IInterceptor[] interceptors) { return(ProtectedCreateClassProxy(target?.GetType(), target, options, interceptors)); }
public TClass CreateClassProxyWithTarget <TClass>(TClass target, ProxyGeneratorOptions options, params IInterceptor[] interceptors) where TClass : class { return((TClass)ProtectedCreateClassProxy(typeof(TClass), target, options, interceptors)); }
public object CreateClassProxy(Type parentType, ProxyGeneratorOptions options, IInterceptor[] interceptors) { return(ProtectedCreateClassProxy(parentType, null, options, interceptors)); }
public TClass CreateClassProxy <TClass>(ProxyGeneratorOptions options, params IInterceptor[] interceptors) where TClass : class { return((TClass)ProtectedCreateClassProxy(typeof(TClass), null, options, interceptors)); }
public ProxyTypeDefinition GetTypeDefinition(Type type, object target, ProxyGeneratorOptions options) { return(moduleDefinition.GetTypeDefinition(type, target?.GetType(), options)); }
public object CreateInterfaceProxyWithoutTarget(Type interfaceType, ProxyGeneratorOptions options, IInterceptor[] interceptors) { return(ProtectedCreateInterfaceProxy(interfaceType, null, options, interceptors)); }
public TInterface CreateInterfaceProxyWithoutTarget <TInterface>(ProxyGeneratorOptions options, params IInterceptor[] interceptors) where TInterface : class { return((TInterface)ProtectedCreateInterfaceProxy(typeof(TInterface), null, options, interceptors)); }