示例#1
0
        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);
        }