private void OverrideEventMethod(MethodInfo method, int count) { if (method != null && MethodOverride.MethodCanBeIntercepted(method)) { new MethodOverride(typeBuilder, proxyInterceptionPipelineField, method, targetType, mainTypeMapper, count).AddMethod(); } }
private IEnumerable <MethodImplementationInfo> DoGetInterceptableMethods(Type implementationType) { var interceptableMethodsToInterfaceMap = new Dictionary <MethodInfo, MethodInfo>(); foreach (MethodInfo method in implementationType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { if (MethodOverride.MethodCanBeIntercepted(method)) { interceptableMethodsToInterfaceMap[method] = null; } } foreach (Type itf in implementationType.GetInterfaces()) { var mapping = implementationType.GetInterfaceMap(itf); for (int i = 0; i < mapping.InterfaceMethods.Length; ++i) { if (interceptableMethodsToInterfaceMap.ContainsKey(mapping.TargetMethods[i])) { interceptableMethodsToInterfaceMap[mapping.TargetMethods[i]] = mapping.InterfaceMethods[i]; } } } foreach (var kvp in interceptableMethodsToInterfaceMap) { yield return(new MethodImplementationInfo(kvp.Value, kvp.Key)); } }
private IEnumerable <MethodInfo> GetMethodsToIntercept() { List <MethodInfo> methodsToIntercept = new List <MethodInfo>(); foreach (MethodInfo method in typeToIntercept.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (!method.IsSpecialName && MethodOverride.MethodCanBeIntercepted(method)) { methodsToIntercept.Add(method); } } MethodSorter sorter = new MethodSorter(typeToIntercept, methodsToIntercept); foreach (MethodInfo method in sorter) { yield return(method); } }