Inheritance: System.Attribute
Example #1
0
        public void Register(string name, Assembly assembly)
        {
            this.eventInfo = new Dictionary <Type, EntityTypeInfo>();

            this.assemblies[name] = assembly;

            foreach (Assembly ass in this.assemblies.Values)
            {
                Type[] types = ass.GetTypes();
                foreach (Type type in types)
                {
                    object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;

                    Type type2 = entityEventAttribute.ClassType;

                    if (!this.eventInfo.ContainsKey(type2))
                    {
                        this.eventInfo.Add(type2, new EntityTypeInfo());
                    }

                    foreach (
                        MethodInfo methodInfo in
                        type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public |
                                        BindingFlags.DeclaredOnly))
                    {
                        int n = methodInfo.GetParameters().Length;
                        if (methodInfo.IsStatic)
                        {
                            --n;
                        }
                        string sn = n > 0? $"{methodInfo.Name}{n}" : methodInfo.Name;
                        foreach (string s in Enum.GetNames(typeof(EntityEventType)))
                        {
                            if (s != sn)
                            {
                                continue;
                            }
                            EntityEventType t = EnumHelper.FromString <EntityEventType>(s);
                            this.eventInfo[type2].Add(t, methodInfo);
                            break;
                        }
                    }
                }
            }

            this.Load();
        }
        public void LoadAssemblyInfo()
        {
            this.eventInfo           = new Dictionary <int, EntityTypeInfo>();
            this.typeToEntityEventId = new Dictionary <Type, int>();

            Type[]        types         = DllHelper.GetBaseTypes();
            List <string> allEntityType = Enum.GetNames(typeof(EntityEventType)).ToList();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
                if (attrs.Length == 0)
                {
                    continue;
                }

                EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;

                int entityEventId = entityEventAttribute.ClassType;

                this.typeToEntityEventId[type] = entityEventId;

                if (!this.eventInfo.ContainsKey(entityEventId))
                {
                    this.eventInfo.Add(entityEventId, new EntityTypeInfo());
                }

                MethodInfo[] methodInfos = type.GetMethods(
                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.InvokeMethod |
                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
                foreach (MethodInfo methodInfo in methodInfos)
                {
                    int n = methodInfo.GetParameters().Length;
                    if (methodInfo.IsStatic)
                    {
                        --n;
                    }

                    string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
                    if (!allEntityType.Contains(sn))
                    {
                        continue;
                    }

                    EntityEventType t = EnumHelper.FromString <EntityEventType>(sn);
                    this.eventInfo[entityEventId].Add(t, new MonoCommonMethod(methodInfo));
                }
            }

#if !SERVER
            if (this.appDomain == null)
            {
                return;
            }

            IType[] ilTypes = this.appDomain.LoadedTypes.Values.ToArray();
            foreach (IType itype in ilTypes)
            {
                Type     type  = itype.ReflectionType;
                object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
                if (attrs.Length == 0)
                {
                    continue;
                }

                EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;

                int entityEventId = entityEventAttribute.ClassType;

                if (!this.eventInfo.ContainsKey(entityEventId))
                {
                    this.eventInfo.Add(entityEventId, new EntityTypeInfo());
                }

                foreach (IMethod methodInfo in itype.GetMethods())
                {
                    int n = methodInfo.ParameterCount;
                    if (methodInfo.IsStatic)
                    {
                        --n;
                    }

                    string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
                    if (!allEntityType.Contains(sn))
                    {
                        continue;
                    }

                    EntityEventType t = EnumHelper.FromString <EntityEventType>(sn);
                    this.eventInfo[entityEventId].Add(t, new ILCommonMethod(methodInfo, n));
                }
            }
#endif
        }