예제 #1
0
 private static void RegisterType(Type type, bool bIsAgentType)
 {
     Attribute[] array = (Attribute[])type.GetCustomAttributes(typeof(TypeMetaInfoAttribute), false);
     if (!bIsAgentType || array.Length > 0)
     {
         TypeMetaInfoAttribute      typeMetaInfoAttribute = (array.Length <= 0) ? null : ((TypeMetaInfoAttribute)array[0]);
         Agent.CTagObjectDescriptor descriptorByName      = Agent.GetDescriptorByName(type.get_FullName());
         if (type.get_BaseType() == typeof(Agent) || type.get_BaseType().IsSubclassOf(typeof(Agent)))
         {
             Agent.CTagObjectDescriptor descriptorByName2 = Agent.GetDescriptorByName(type.get_BaseType().get_FullName());
             descriptorByName.m_parent = descriptorByName2;
         }
         descriptorByName.type        = type;
         descriptorByName.displayName = ((typeMetaInfoAttribute != null && !string.IsNullOrEmpty(typeMetaInfoAttribute.DisplayName)) ? typeMetaInfoAttribute.DisplayName : type.get_FullName());
         descriptorByName.desc        = ((typeMetaInfoAttribute != null && !string.IsNullOrEmpty(typeMetaInfoAttribute.Description)) ? typeMetaInfoAttribute.Description : descriptorByName.displayName);
         if (Utils.IsEnumType(type))
         {
             return;
         }
         BindingFlags bindingFlags = 62;
         FieldInfo[]  fields       = type.GetFields(bindingFlags);
         FieldInfo[]  array2       = fields;
         for (int i = 0; i < array2.Length; i++)
         {
             FieldInfo fieldInfo       = array2[i];
             bool      flag            = false;
             MemberMetaInfoAttribute a = null;
             if (bIsAgentType)
             {
                 Attribute[] array3 = (Attribute[])fieldInfo.GetCustomAttributes(typeof(MemberMetaInfoAttribute), false);
                 if (array3.Length > 0)
                 {
                     a    = (MemberMetaInfoAttribute)array3[0];
                     flag = true;
                 }
             }
             else
             {
                 flag = true;
             }
             if (flag)
             {
                 CMemberBase cMemberBase = new CMemberBase(fieldInfo, a);
                 for (int j = 0; j < descriptorByName.ms_members.get_Count(); j++)
                 {
                     if (cMemberBase.GetId() == descriptorByName.ms_members.get_Item(j).GetId())
                     {
                         CMemberBase cMemberBase2 = descriptorByName.ms_members.get_Item(j);
                         break;
                     }
                 }
                 descriptorByName.ms_members.Add(cMemberBase);
                 if ((Utils.IsCustomClassType(fieldInfo.get_FieldType()) || Utils.IsEnumType(fieldInfo.get_FieldType())) && !Agent.IsTypeRegisterd(fieldInfo.get_FieldType().get_FullName()))
                 {
                     Workspace.RegisterType(fieldInfo.get_FieldType(), false);
                 }
             }
         }
         if (bIsAgentType)
         {
             MethodInfo[] methods = type.GetMethods(bindingFlags);
             MethodInfo[] array4  = methods;
             for (int k = 0; k < array4.Length; k++)
             {
                 MethodInfo  methodInfo = array4[k];
                 Attribute[] array5     = (Attribute[])methodInfo.GetCustomAttributes(typeof(MethodMetaInfoAttribute), false);
                 if (array5.Length > 0)
                 {
                     MethodMetaInfoAttribute a2          = (MethodMetaInfoAttribute)array5[0];
                     CMethodBase             cMethodBase = new CMethodBase(methodInfo, a2, null);
                     descriptorByName.ms_methods.Add(cMethodBase);
                     ParameterInfo[] parameters = methodInfo.GetParameters();
                     ParameterInfo[] array6     = parameters;
                     for (int l = 0; l < array6.Length; l++)
                     {
                         ParameterInfo parameterInfo = array6[l];
                         if ((Utils.IsCustomClassType(parameterInfo.get_ParameterType()) || Utils.IsEnumType(parameterInfo.get_ParameterType())) && !Agent.IsTypeRegisterd(parameterInfo.get_ParameterType().get_FullName()))
                         {
                             Workspace.RegisterType(parameterInfo.get_ParameterType(), false);
                         }
                     }
                     if ((Utils.IsCustomClassType(methodInfo.get_ReturnType()) || Utils.IsEnumType(methodInfo.get_ReturnType())) && !Agent.IsTypeRegisterd(methodInfo.get_ReturnType().get_FullName()))
                     {
                         Workspace.RegisterType(methodInfo.get_ReturnType(), false);
                     }
                 }
             }
             Type[] nestedTypes = type.GetNestedTypes(bindingFlags);
             Type[] array7      = nestedTypes;
             for (int m = 0; m < array7.Length; m++)
             {
                 Type        type2  = array7[m];
                 Attribute[] array8 = (Attribute[])type2.GetCustomAttributes(typeof(EventMetaInfoAttribute), false);
                 if (array8.Length > 0)
                 {
                     EventMetaInfoAttribute a3          = (EventMetaInfoAttribute)array8[0];
                     MethodInfo             method      = type2.GetMethod("Invoke");
                     CNamedEvent            cNamedEvent = new CNamedEvent(method, a3, type2.get_Name());
                     descriptorByName.ms_methods.Add(cNamedEvent);
                 }
             }
         }
     }
 }
예제 #2
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);
                }
            }
        }