private static Dictionary<MethodInfo, MethodMappings> GetTargetMethods(Type targetType) { var targets = new Dictionary<MethodInfo, MethodMappings>(); foreach (var interfaceOnTarget in targetType.GetInterfaces()) { if (interfaceOnTarget.IsPublic) { var mapping = targetType.GetInterfaceMap(interfaceOnTarget); for (int i = 0; i < mapping.InterfaceMethods.Length; i++) { MethodInfo trueTarget; if (mapping.TargetMethods[i].IsPublic) { // We can invoke the true target // so the mapping will be directly to the target method. // Note that I don't care if it's final or not. trueTarget = mapping.TargetMethods[i]; } else { trueTarget = mapping.InterfaceMethods[i]; } MethodMappings methodMapping = null; if (!targets.ContainsKey(trueTarget)) { methodMapping = new MethodMappings(true); targets.Add(trueTarget, methodMapping); } else { methodMapping = targets[trueTarget]; } methodMapping.MappedMethods.Add(mapping.InterfaceMethods[i]); } } } foreach (var methodInfo in targetType.GetMethods()) { if (methodInfo.IsPublic && methodInfo.IsVirtual && !methodInfo.IsFinal) { // Let's see if we already have it // from the interface mapping. MethodMappings baseMethodMapping = null; if (!targets.ContainsKey(methodInfo)) { // This method doesn't override // any itf. methods, so add it. baseMethodMapping = new MethodMappings(false); targets.Add(methodInfo, baseMethodMapping); baseMethodMapping.MappedMethods.Add(methodInfo); } } } return targets; }
private static Dictionary <MethodInfo, MethodMappings> GetTargetMethods(Type targetType) { var targets = new Dictionary <MethodInfo, MethodMappings>(); foreach (var interfaceOnTarget in targetType.GetInterfaces()) { if (interfaceOnTarget.IsPublic) { var mapping = targetType.GetInterfaceMap(interfaceOnTarget); for (int i = 0; i < mapping.InterfaceMethods.Length; i++) { MethodInfo trueTarget; if (mapping.TargetMethods[i].IsPublic) { // We can invoke the true target // so the mapping will be directly to the target method. // Note that I don't care if it's final or not. trueTarget = mapping.TargetMethods[i]; } else { trueTarget = mapping.InterfaceMethods[i]; } MethodMappings methodMapping = null; if (!targets.ContainsKey(trueTarget)) { methodMapping = new MethodMappings(true); targets.Add(trueTarget, methodMapping); } else { methodMapping = targets[trueTarget]; } methodMapping.MappedMethods.Add(mapping.InterfaceMethods[i]); } } } foreach (var methodInfo in targetType.GetMethods()) { if (methodInfo.IsPublic && methodInfo.IsVirtual && !methodInfo.IsFinal) { // Let's see if we already have it // from the interface mapping. MethodMappings baseMethodMapping = null; if (!targets.ContainsKey(methodInfo)) { // This method doesn't override // any itf. methods, so add it. baseMethodMapping = new MethodMappings(false); targets.Add(methodInfo, baseMethodMapping); baseMethodMapping.MappedMethods.Add(methodInfo); } } } return(targets); }