Esempio n. 1
0
        internal static void AddEntityStatic(Type tp)
        {
            FieldInfo[] fields = tp.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
            if (fields != null && fields.Length > 0)
            {
                foreach (var field in fields)
                {
                    if (field.IsStatic)
                    {
                        object[] objs = field.GetCustomAttributes(typeof(TriggerEmmiter), true);
                        if (objs != null && objs.Length > 0)
                        {
                            Emmiter data = (Emmiter)field.GetValue(null);
                            if (data == null)
                            {
                                string warnstr = string.Format("Warning : DataEntity({0}.{1}) is null when scan type!", tp.Name, field.Name);
                                Logger.warning(warnstr);
                            }
                            else
                            {
                                data.Type = ((TriggerEmmiter)objs[0]).dataType;

                                Entity entity = new Entity();
                                entity.instance = null;
                                entity.data     = data;
                                mDataEntities.Add(data.Type, entity);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        internal static void AddEntityWithInstance(object instance)
        {
            Type tp       = instance.GetType();
            Type baseType = typeof(Emmiter);

            FieldInfo[] fields = tp.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            if (fields != null && fields.Length > 0)
            {
                foreach (var field in fields)
                {
                    if (!field.IsStatic)
                    {
                        object[] objs = field.GetCustomAttributes(typeof(TriggerEmmiter), true);
                        if (objs != null && objs.Length > 0)
                        {
                            try
                            {
                                if (field.FieldType.IsSubclassOf(baseType) || field.FieldType == baseType)
                                {
                                    Emmiter data = (Emmiter)field.GetValue(instance);
                                    if (data == null)
                                    {
                                        string warnstr = string.Format("Warning : DataEntity({0}.{1}) is null when class construct!", tp.Name, field.Name);
                                        Logger.warning(warnstr);
                                    }
                                    else
                                    {
                                        data.Type = ((TriggerEmmiter)objs[0]).dataType;
                                        if (!mDataEntities.ContainsKey(data.Type))
                                        {
                                            Entity entity = new Entity();
                                            entity.instance = instance;
                                            entity.data     = data;
                                            mDataEntities.Add(data.Type, entity);
                                        }
                                    }
                                }
                                else
                                {
                                    string warnstr = string.Format("Warning : DataEntity({0}.{1}) is invalid, field must be child class of AData", tp.Name, field.Name);
                                    Logger.error(warnstr);
                                }
                            }
                            catch (Exception exc)
                            {
                                Logger.error(exc.Message + " Field Error!(" + field.Name + ")");
                            }
                        }
                    }
                }
            }
        }