public static ProxifierWithBaseClass <T> For <T>(IProxyAction action) where T : class { if (typeof(T).GetTypeInfo().IsInterface) { throw new ArgumentException("Proxy base type cannot be an interface"); } if (action == null) { throw new ArgumentNullException("Proxy action is undefined"); } return(new ProxifierWithBaseClass <T>(action)); }
internal Object Create(Type baseClass, IList <Type> implementedInterfaces, IProxyAction action) { String proxyTypeName = baseClass.FullName + "__Proxy"; TypeAttributes proxyTypeAttr = TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public; var typeBuilder = moduleBuilder.DefineType(proxyTypeName, proxyTypeAttr, baseClass, implementedInterfaces.ToArray()); var callbackType = typeof(IProxyAction); var callbackField = typeBuilder.DefineField("proxy__callback", callbackType, FieldAttributes.Private); defineConstructor(typeBuilder, callbackField); overrideVirtualMethods(typeBuilder, baseClass, callbackField); foreach (var @interface in implementedInterfaces) { overrideVirtualMethods(typeBuilder, @interface, callbackField); } var proxyType = typeBuilder.CreateTypeInfo(); return(proxyType.GetConstructor(new Type[] { callbackType }).Invoke(new Object[] { action })); }
public ProxifierWithBaseClass(IProxyAction action) { this.action = action; }
public static ProxifierWithBaseClass <Object> WithoutBaseClass(IProxyAction action) { return(new ProxifierWithBaseClass <Object>(action)); }