Exemplo n.º 1
0
        private static void RegisterMetas(Assembly a)
        {
            ListView <Type> listView = new ListView <Type>();

            Type[] types = a.GetTypes();
            Type[] array = types;
            for (int i = 0; i < array.Length; i++)
            {
                Type type3 = array[i];
                if ((type3.IsSubclassOf(typeof(Agent)) || Utils.IsStaticType(type3)) && !Workspace.IsRegisterd(type3))
                {
                    Attribute[] array2 = (Attribute[])type3.GetCustomAttributes(typeof(TypeMetaInfoAttribute), false);
                    if (array2.Length > 0)
                    {
                        Workspace.TypeInfo_t typeInfo_t = new Workspace.TypeInfo_t();
                        typeInfo_t.type = type3;
                        Workspace.ms_agentTypes.Add(typeInfo_t);
                        if (type3.get_BaseType() != null && (type3.get_BaseType() == typeof(Agent) || type3.get_BaseType().IsSubclassOf(typeof(Agent))))
                        {
                            listView.Add(type3.get_BaseType());
                        }
                        if (Utils.IsStaticType(type3))
                        {
                            TypeMetaInfoAttribute typeMetaInfoAttribute = array2[0] as TypeMetaInfoAttribute;
                            Agent.RegisterStaticClass(type3, typeMetaInfoAttribute.DisplayName, typeMetaInfoAttribute.Description);
                        }
                    }
                }
            }
            using (ListView <Type> .Enumerator enumerator = listView.GetEnumerator())
            {
                Type type;
                while (enumerator.MoveNext())
                {
                    type = enumerator.get_Current();
                    if (!Workspace.IsRegisterd(type) && Workspace.ms_agentTypes.Find((Workspace.TypeInfo_t t) => t.type == type) == null)
                    {
                        Workspace.TypeInfo_t typeInfo_t2 = new Workspace.TypeInfo_t();
                        typeInfo_t2.type         = type;
                        typeInfo_t2.bIsInherited = true;
                        Workspace.ms_agentTypes.Add(typeInfo_t2);
                    }
                }
            }
            Workspace.ms_agentTypes.Sort(delegate(Workspace.TypeInfo_t x, Workspace.TypeInfo_t y)
            {
                if (x.bIsInherited && !y.bIsInherited)
                {
                    return(-1);
                }
                if (!x.bIsInherited && y.bIsInherited)
                {
                    return(1);
                }
                if (x.type.IsSubclassOf(y.type))
                {
                    return(1);
                }
                if (y.type.IsSubclassOf(x.type))
                {
                    return(-1);
                }
                return(x.type.get_FullName().CompareTo(y.type.get_FullName()));
            });
            using (List <Workspace.TypeInfo_t> .Enumerator enumerator2 = Workspace.ms_agentTypes.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    Workspace.TypeInfo_t current = enumerator2.get_Current();
                    Type type2 = current.type;
                    Workspace.RegisterType(type2, true);
                }
            }
        }