示例#1
0
        public TypedMessageInfo DescribeMessage(string message, Type[] args)
        {
            foreach (IMessageStore store in List)
            {
                ITypedMessageStore typed_store = store as ITypedMessageStore;
                if (typed_store == null)
                {
                    continue;
                }

                TypedMessageInfo info = typed_store.DescribeMessage(message, args);
                if (info != null)
                {
                    return(info);
                }
            }

            return(null);
        }
示例#2
0
		private MessageInfo[] ListMessages (string opt_filter) {
			ICollection method_list;
			if (obj == null) {
				ArrayList list = new ArrayList (obj_type.GetMethods ());
				list.InsertRange (list.Count, typeof (Type).GetMethods ());
				method_list = list;
			} else {
				method_list = obj_type.GetMethods ();
			}

			ArrayList info_list = new ArrayList ();
			Hashtable methods = new Hashtable (); 

			if (opt_filter != String.Empty) {
				opt_filter = opt_filter.ToLower ();
			}

			foreach (MethodInfo method in method_list)
			{
				string method_lower = method.Name.ToLower ();
				if (opt_filter != String.Empty && method.Name.ToLower () != opt_filter)
					continue;

				MessageInfo info = (MessageInfo) methods[method_lower];
				if (info == null) {
					info = new TypedMessageInfo ();
					info.message = method.Name;
					info.min_argc = -1;
					info.default_argc = -1;
					info.max_argc = 0;
					methods[method_lower] = info;
					info_list.Add (info);
				}

				ParameterInfo[] parms = method.GetParameters ();
				int count = (parms != null) ? parms.Length : 0;

				if (count > 0) {
					object[] attrs = parms[count - 1].GetCustomAttributes (typeof (System.ParamArrayAttribute), true);
					if (attrs != null && attrs.Length > 0) 
						info.max_argc = -1;
				}

				object[] method_attrs = method.GetCustomAttributes (typeof (PassContextAttribute), true);
				if (method_attrs != null && method_attrs.Length > 0) {
					count--;
				}
		
				if (info.min_argc == -1 || count <= info.min_argc) {
					info.min_argc = count;
					info.default_argc = count;
				}

				method_attrs = method.GetCustomAttributes (typeof (DefaultArgumentCountAttribute), true);
				if (method_attrs != null && method_attrs.Length > 0) {
					info.default_argc = ((DefaultArgumentCountAttribute) method_attrs[0]).DefaultCount;
				}
			
				if (info.max_argc != -1 && count > info.max_argc) {
					info.max_argc = count;
				}
			}

			MessageInfo[] ret = new MessageInfo[info_list.Count];
			info_list.CopyTo (ret, 0);
			return ret;
		}
示例#3
0
        private MessageInfo[] ListMessages(string opt_filter)
        {
            ICollection method_list;

            if (obj == null)
            {
                ArrayList list = new ArrayList(obj_type.GetMethods());
                list.InsertRange(list.Count, typeof(Type).GetMethods());
                method_list = list;
            }
            else
            {
                method_list = obj_type.GetMethods();
            }

            ArrayList info_list = new ArrayList();
            Hashtable methods   = new Hashtable();

            if (opt_filter != String.Empty)
            {
                opt_filter = opt_filter.ToLower();
            }

            foreach (MethodInfo method in method_list)
            {
                string method_lower = method.Name.ToLower();
                if (opt_filter != String.Empty && method.Name.ToLower() != opt_filter)
                {
                    continue;
                }

                MessageInfo info = (MessageInfo)methods[method_lower];
                if (info == null)
                {
                    info                  = new TypedMessageInfo();
                    info.message          = method.Name;
                    info.min_argc         = -1;
                    info.default_argc     = -1;
                    info.max_argc         = 0;
                    methods[method_lower] = info;
                    info_list.Add(info);
                }

                ParameterInfo[] parms = method.GetParameters();
                int             count = (parms != null) ? parms.Length : 0;

                if (count > 0)
                {
                    object[] attrs = parms[count - 1].GetCustomAttributes(typeof(System.ParamArrayAttribute), true);
                    if (attrs != null && attrs.Length > 0)
                    {
                        info.max_argc = -1;
                    }
                }

                object[] method_attrs = method.GetCustomAttributes(typeof(PassContextAttribute), true);
                if (method_attrs != null && method_attrs.Length > 0)
                {
                    count--;
                }

                if (info.min_argc == -1 || count <= info.min_argc)
                {
                    info.min_argc     = count;
                    info.default_argc = count;
                }

                method_attrs = method.GetCustomAttributes(typeof(DefaultArgumentCountAttribute), true);
                if (method_attrs != null && method_attrs.Length > 0)
                {
                    info.default_argc = ((DefaultArgumentCountAttribute)method_attrs[0]).DefaultCount;
                }

                if (info.max_argc != -1 && count > info.max_argc)
                {
                    info.max_argc = count;
                }
            }

            MessageInfo[] ret = new MessageInfo[info_list.Count];
            info_list.CopyTo(ret, 0);
            return(ret);
        }