private static MethodAttribute GetMethodAttribute(MethodInfo method)
 {
     object[] attrs = method.GetCustomAttributes(typeof(MethodAttribute), true);
     if (attrs != null && attrs.Length > 0)
     {
         foreach (object o in attrs)
         {
             MethodAttribute attr = o as MethodAttribute;
             if (attr != null)
             {
                 return(attr);
             }
         }
     }
     return(null);
 }
        private static MethodInfoCollection GetMethodCollectionAndCache(InvokeContextBase context, Type type)
        {
            MethodCache          cache = GetMethodCache(type);
            MethodInfoCollection infos = GetMethodCollection(cache, type, context.MethodName);

            if (infos == null)
            {
                lock (_syncMethodObject)
                {
                    infos = GetMethodCollection(cache, type, context.MethodName);
                    if (infos == null)
                    {
                        infos = new MethodInfoCollection();
                        MemberInfo[] methods = type.GetMembers(_defaultBinding);
                        int          index   = 0;
                        if (methods != null && methods.Length > 0)
                        {
                            foreach (MemberInfo info in methods)
                            {
                                index++;
                                if (index < 0)
                                {
                                    break;
                                }
                                if (info.MemberType == MemberTypes.Method)
                                {
                                    MethodInfo      method = (MethodInfo)info;
                                    MethodAttribute attr   = GetMethodAttribute(method);
                                    if (attr != null && string.Compare(attr.MethodName, context.MethodName, true) == 0)
                                    {
                                        infos.Add(method);
                                    }
                                    else if (string.Compare(info.Name, context.MethodName, true) == 0)
                                    {
                                        infos.Add(method);
                                    }
                                }
                            }
                        }
                        cache[context.MethodName] = infos;
                    }
                }
            }
            return(infos);
        }