Beispiel #1
0
 /// <summary>
 /// Recurses through interface graph accumulating methods
 /// </summary>
 /// <param name="grainType">Grain type</param>
 /// <param name="serviceType">Service interface type</param>
 /// <param name="methodInfos">Accumulated </param>
 private static void GetMethodsImpl(Type grainType, Type serviceType, List <MethodInfo> methodInfos)
 {
     foreach (var iType in GetRemoteInterfaces(serviceType, false))
     {
         if (grainType.IsClass)
         {
             var mapping = grainType.GetInterfaceMap(iType);
             foreach (var methodInfo in iType.GetMethods(BindingFlags.Instance | BindingFlags.Public))
             {
                 foreach (var info in mapping.TargetMethods)
                 {
                     if (info.DeclaringType == grainType && MethodComparer.Equals(methodInfo, info))
                     {
                         if (!methodInfos.Contains(methodInfo, MethodComparer))
                         {
                             methodInfos.Add(methodInfo);
                         }
                         break;
                     }
                 }
             }
         }
         else if (grainType.IsInterface)
         {
             foreach (var methodInfo in iType.GetMethods(BindingFlags.Instance | BindingFlags.Public))
             {
                 if (!methodInfos.Contains(methodInfo, MethodComparer))
                 {
                     methodInfos.Add(methodInfo);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Recurses through interface graph accumulating methods
        /// </summary>
        /// <param name="grainType">Grain type</param>
        /// <param name="serviceType">Service interface type</param>
        /// <param name="methodInfos">Accumulated </param>
        private static void GetMethodsImpl(Type grainType, Type serviceType, List <MethodInfo> methodInfos)
        {
            Type[] iTypes = GetRemoteInterfaces(serviceType, false).Values.ToArray();
            IEqualityComparer <MethodInfo> methodComparer = new MethodInfoComparer();

            var typeInfo = grainType.GetTypeInfo();

            foreach (Type iType in iTypes)
            {
                var mapping = new InterfaceMapping();

                if (typeInfo.IsClass)
                {
                    mapping = typeInfo.GetRuntimeInterfaceMap(iType);
                }

                if (typeInfo.IsInterface || mapping.TargetType == grainType)
                {
                    foreach (var methodInfo in iType.GetMethods())
                    {
                        if (typeInfo.IsClass)
                        {
                            var mi    = methodInfo;
                            var match = mapping.TargetMethods.Any(info => methodComparer.Equals(mi, info) &&
                                                                  info.DeclaringType == grainType);

                            if (match)
                            {
                                if (!methodInfos.Contains(mi, methodComparer))
                                {
                                    methodInfos.Add(mi);
                                }
                            }
                        }
                        else if (!methodInfos.Contains(methodInfo, methodComparer))
                        {
                            methodInfos.Add(methodInfo);
                        }
                    }
                }
            }
        }