public static TInterface Create<TInterface>() where TInterface : class { VerifyInterfaceType(typeof(TInterface)); var attribute = GetInterfacerAttribute(typeof(TInterface)); if (attribute is ApplyToInstanceAttribute) { var wrappedObject = Activator.CreateInstance(attribute.Class); return (TInterface) ValueConverter .For(attribute.Class, wrappedObject) .To(typeof(TInterface)) .Convert() .Value; } if (attribute is ApplyToStaticAttribute) { var proxyGenerator = new ProxyGenerator(); var proxy = proxyGenerator.CreateResolvableInterfaceProxyWithoutTarget<TInterface>(new StaticProxy(attribute.Class)); return proxy; } throw new NotImplementedException(); }
private object CreateInstanceProxyForObject(Type interfacerType, object wrappedObject) { var proxyGenerator = new ProxyGenerator(); var proxy = proxyGenerator.CreateResolvableInterfaceProxyWithoutTarget(interfacerType, new[] { typeof(ICanGetWrappedObject) }, new InstanceProxy(wrappedObject)); return(proxy); }
public static object Create(Type type) { VerifyInterfaceType(type); var attribute = GetInterfacerAttribute(type); if (attribute is ApplyToInstanceAttribute) { var wrappedObject = Activator.CreateInstance(attribute.Class); return(ValueConverter .For(attribute.Class, wrappedObject) .To(type) .Convert() .Value); } if (attribute is ApplyToStaticAttribute) { var proxyGenerator = new ProxyGenerator(); var proxy = proxyGenerator.CreateResolvableInterfaceProxyWithoutTarget(type, null, new StaticProxy(attribute.Class)); return(proxy); } throw new NotImplementedException(); }
public static TInterface CreateResolvableInterfaceProxyWithoutTarget <TInterface>( this ProxyGenerator proxyGenerator, params IInterceptor[] interceptors) where TInterface : class { return((TInterface)proxyGenerator.CreateResolvableInterfaceProxyWithoutTarget(typeof(TInterface), null, interceptors)); }