/// <summary> /// Performs some basic screening and invokes the <see cref = "IProxyGenerationHook" /> /// to select methods. /// </summary> /// <param name = "method"></param> /// <param name = "onlyVirtuals"></param> /// <param name = "hook"></param> /// <returns></returns> protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook) { if (IsInternalAndNotVisibleToDynamicProxy(method)) { return(false); } var isOverridable = method.IsVirtual && !method.IsFinal; if (onlyVirtuals && !isOverridable) { if ( #if !SILVERLIGHT method.DeclaringType != typeof(MarshalByRefObject) && #endif method.IsGetType() == false && method.IsMemberwiseClone() == false) { Logger.DebugFormat("Excluded non-overridable method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); hook.NonProxyableMemberNotification(type, method); } return(false); } // we can never intercept a sealed (final) method if (method.IsFinal) { Logger.DebugFormat("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); return(false); } //can only proxy methods that are public or protected (or internals that have already been checked above) if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false) { return(false); } #if !SILVERLIGHT if (method.DeclaringType == typeof(MarshalByRefObject)) { return(false); } #endif if (method.IsFinalizer()) { return(false); } return(hook.ShouldInterceptMethod(type, method)); }
private void CollectFields(IProxyGenerationHook hook) { var fields = Type.GetAllFields(); foreach (var field in fields) { if (IsOKToBeOnProxy(field)) { continue; } hook.NonProxyableMemberNotification(Type, field); } }
private void CollectFields(IProxyGenerationHook hook) { var fields = type.GetAllFields(); foreach (var field in fields) { if (IsOKToBeOnProxy(field)) { continue; } hook.NonProxyableMemberNotification(type, field); } }
public void NonProxyableMemberNotification(Type type, MemberInfo memberInfo) { if (hook != null) { //give the inner hook a chance to throw its own exception hook.NonProxyableMemberNotification(type, memberInfo); } // actually we should never get this, since we're doing an interface proxy // so if we do, this may mean it's a bug. throw new NotSupportedException( string.Format("Member {0}.{1} is non virtual hence can not be proxied. If you think it's a bug, please report it.", type.FullName, memberInfo.Name)); }
/// <summary> /// Performs some basic screening and invokes the <see cref = "IProxyGenerationHook" /> /// to select methods. /// </summary> /// <param name = "method"></param> /// <param name = "onlyVirtuals"></param> /// <param name = "hook"></param> /// <returns></returns> protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook) { // we can never intercept a sealed (final) method if (method.IsFinal) { Logger.DebugFormat("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); return false; } if (IsInternalAndNotVisibleToDynamicProxy(method)) { return false; } if (onlyVirtuals && !method.IsVirtual) { if ( #if !SILVERLIGHT method.DeclaringType != typeof(MarshalByRefObject) && #endif method.IsGetType() == false && method.IsMemberwiseClone() == false) { Logger.DebugFormat("Excluded non-virtual method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName); hook.NonProxyableMemberNotification(type, method); } return false; } //can only proxy methods that are public or protected (or internals that have already been checked above) if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false) { return false; } #if !SILVERLIGHT if (method.DeclaringType == typeof(MarshalByRefObject)) { return false; } #endif if (method.IsFinalizer()) { return false; } return hook.ShouldInterceptMethod(type, method); }
//internal static void Emit(this ILGenerator gen, OpCode opcode, IConstructorInfo con) //{ // gen.Emit(opcode, con.AsConstructorInfo()); //} //internal static void Emit(this ILGenerator gen, OpCode opcode, IFieldInfo field) //{ // gen.Emit(opcode, field.AsFieldInfo()); //} //internal static void Emit(this ILGenerator gen, OpCode opcode, IMethodInfo method) //{ // gen.Emit(opcode, method.AsMethodInfo()); //} internal static void NonProxyableMemberNotification(this IProxyGenerationHook hook, Type type, MemberInfo memberInfo) { hook.NonProxyableMemberNotification(type, memberInfo.AsIMemberInfo()); }