Ejemplo n.º 1
0
        public static Dictionary <string, object> getMethods(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            Dictionary <string, object> tempd = new Dictionary <string, object>();

            foreach (var m in obj.GetType().GetMethods())
            {
                if ((!new Regex(RegexStr1).Match(m.DeclaringType.Name).Success) && (!new Regex(RegexStr2).Match(m.DeclaringType.Name).Success) && m.ToString().Substring(0, 4) == RegexStr3 && Regex.IsMatch(m.Name[0].ToString(), "[A-Z]"))
                {
                    if (m.GetParameters().Length == 0)
                    {
                        Funcs funcs1 = new Funcs();

                        funcs1.Func = () =>
                        {
                            m.Invoke(obj, null);
                            return(null);
                        };

                        foreach (var ca in m.CustomAttributes)
                        {
                            if (ca.AttributeType.Name == "Initialize")
                            {
                                if (ca.ConstructorArguments.Count == 1)
                                {
                                    if ((int)(ca.ConstructorArguments[0].Value) == 1)
                                    {
                                        //Do Nothing
                                    }
                                    else if ((int)(ca.ConstructorArguments[0].Value) == 2)
                                    {
                                        funcs1.RunFunc();
                                    }
                                    else if ((int)(ca.ConstructorArguments[0].Value) == 4)
                                    {
                                        Async.RunFuncAsync(funcs1.RunFunc, null);
                                    }
                                }

                                break;
                            }
                        }

                        if (tempd.ContainsKey(m.Name))
                        {
                            Debug.WriteLine("■■■找到重复键:" + m.Name + "。已采用默认值。");
                        }
                        else
                        {
                            tempd.Add(m.Name, new Action(funcs1.RunFunc));
                        }
                    }
                    else
                    {
                        Funcs  funcs2 = new Funcs();
                        object param  = m.GetParameters()[0];

                        funcs2.FuncWithParam = (pam) =>
                        {
                            object[] objs = new object[1];
                            objs[0] = pam;
                            m.Invoke(obj, objs);
                            return(null);
                        };
                        if (tempd.ContainsKey(m.Name))
                        {
                            Debug.WriteLine("■■■找到重复键:" + m.Name + "。已采用默认值。");
                        }
                        else
                        {
                            tempd.Add(m.Name, new Action <object>(funcs2.RunFuncWithParam));
                        }
                    }
                }
            }
            return(tempd);
        }
Ejemplo n.º 2
0
 public TcpIpServer(IPAddress LocalAddr, Int32 Port) : base(LocalAddr, Port)
 {
     Async.RunFuncAsync(ServerStart, null);
 }