Exemple #1
0
    void bindAll(IntPtr l)
    {
        Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies();

        List <Type> bindlist = new List <Type>();

        foreach (Assembly a in ams)
        {
            Type[] ts = a.GetExportedTypes();
            foreach (Type t in ts)
            {
                if (t.GetCustomAttributes(typeof(LuaBinderAttribute), false).Length > 0)
                {
                    bindlist.Add(t);
                }
            }
        }

        bindlist.Sort(new System.Comparison <Type>((Type a, Type b) =>
        {
            LuaBinderAttribute la = (LuaBinderAttribute)a.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0];
            LuaBinderAttribute lb = (LuaBinderAttribute)b.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0];

            return(la.order.CompareTo(lb.order));
        })
                      );

        foreach (Type t in bindlist)
        {
            t.GetMethod("Bind").Invoke(null, new object[] { l });
        }
    }
Exemple #2
0
        private void doBind(object state)
        {
            IntPtr L = (IntPtr)state;

            Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies();

            bindProgress = 0;

            List <Type> bindlist = new List <Type>();

            for (int n = 0; n < ams.Length; n++)
            {
                Assembly a  = ams[n];
                Type[]   ts = null;
                try
                {
                    ts = a.GetExportedTypes();
                }
                catch
                {
                    continue;
                }
                for (int k = 0; k < ts.Length; k++)
                {
                    Type t = ts[k];
                    if (t.GetCustomAttributes(typeof(LuaBinderAttribute), false).Length > 0)
                    {
                        bindlist.Add(t);
                    }
                }
            }

            bindProgress = 1;

            bindlist.Sort(new System.Comparison <Type>((Type a, Type b) => {
                LuaBinderAttribute la = (LuaBinderAttribute)a.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0];
                LuaBinderAttribute lb = (LuaBinderAttribute)b.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0];

                return(la.order.CompareTo(lb.order));
            }));

            List <Action <IntPtr> > list = new List <Action <IntPtr> >();

            for (int n = 0; n < bindlist.Count; n++)
            {
                Type t       = bindlist[n];
                var  sublist = (Action <IntPtr>[])t.GetMethod("GetBindList").Invoke(null, null);
                list.AddRange(sublist);
            }

            bindProgress = 2;

            int count = list.Count;

            try {
                for (int n = 0; n < count; n++)
                {
                    Action <IntPtr> action = list[n];
                    action(L);
                    bindProgress = (int)(((float)n / count) * 98.0) + 2;
                }
            } catch (Exception e) {
                LogUtil.Error(e.ToString());
            }

            bindProgress = 100;
        }