예제 #1
0
 private void OverrideEventMethod(MethodInfo method, int count)
 {
     if (method != null && MethodOverride.MethodCanBeIntercepted(method))
     {
         new MethodOverride(typeBuilder, proxyInterceptionPipelineField, method, targetType, mainTypeMapper, count).AddMethod();
     }
 }
 private void OverridePropertyMethod(MethodInfo method, int count)
 {
     if (method != null && MethodOverride.MethodCanBeIntercepted(method))
     {
         new MethodOverride(typeBuilder, proxyInterceptionPipelineField, method, 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));
            }
        }
예제 #4
0
 private void OverridePropertyMethod(MethodInfo method, int count, FieldBuilder propsField)
 {
     if (method != null && MethodOverride.MethodCanBeIntercepted(method))
     {
         var methodOverride = new MethodOverride(typeBuilder, proxyInterceptionPipelineField, method, targetType, mainTypeMapper, count);
         methodOverride.AddMethod(count, propsField);
         this.methodOverrides.Add(methodOverride);
     }
 }
예제 #5
0
 public IEnumerable <MethodImplementationInfo> GetInterceptableMethods(Type interceptedType, Type implementationType)
 {
     Guard.ArgumentNotNull(interceptedType, "interceptedType");
     Guard.ArgumentNotNull(implementationType, "implementationType");
     foreach (MethodInfo method in implementationType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
     {
         if (MethodOverride.MethodCanBeIntercepted(method))
         {
             yield return(new MethodImplementationInfo(null, method));
         }
     }
 }
예제 #6
0
        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);
            }
        }