internal static int OnSort(System.Reflection.PropertyInfo prop1, System.Reflection.PropertyInfo prop2)
        {
            object[] objs1 = prop1.GetCustomAttributes(false);
            if (objs1 == null)
            {
                return(1);
            }
            object[] objs2 = prop2.GetCustomAttributes(false);
            if (objs2 == null)
            {
                return(-1);
            }
            ConfigIdAttribute attr1 = null;

            for (int i = 0; i < objs1.Length; ++i)
            {
                attr1 = objs1[i] as ConfigIdAttribute;
                if (attr1 != null)
                {
                    break;
                }
            }

            if (attr1 == null)
            {
                return(1);
            }

            ConfigIdAttribute attr2 = null;

            for (int i = 0; i < objs2.Length; ++i)
            {
                attr2 = objs2[i] as ConfigIdAttribute;
                if (attr2 != null)
                {
                    break;
                }
            }

            if (attr2 == null)
            {
                return(-1);
            }

            return((int)attr1.ID - (int)attr2.ID);
        }
Example #2
0
        private bool InitPropertys()
        {
            // 一个类型值只读一次
            var m_Props = Propertys;

            if (m_Props == null)
            {
                System.Type type = GetType();
                System.Reflection.PropertyInfo[] props =
                    type.GetProperties(System.Reflection.BindingFlags.Public |
                                       System.Reflection.BindingFlags.Instance |
                                       System.Reflection.BindingFlags.SetProperty |
                                       System.Reflection.BindingFlags.GetProperty);
                if (props == null || props.Length <= 0)
                {
                    return(false);
                }
                m_Props = new List <System.Reflection.PropertyInfo>();
                for (int i = 0; i < props.Length; ++i)
                {
                    var      prop  = props[i];
                    object[] attrs = prop.GetCustomAttributes(false);
                    if (attrs != null && attrs.Length > 0)
                    {
                        for (int j = 0; j < attrs.Length; ++j)
                        {
                            ConfigIdAttribute attr = attrs[j] as ConfigIdAttribute;
                            if (attr != null)
                            {
                                m_Props.Add(prop);
                                break;
                            }
                        }
                    }
                }
                m_Props.Sort(ConfigIdAttribute.OnSort);
                Propertys = m_Props;
            }
            return(m_Props != null && m_Props.Count > 0);
        }
        // 检查
        private static void PrintCheckErrorPropertys(string str, System.Type tt)
        {
            // 字段和Property的名字
            List <string> fieldAndPropNamesNoConfigId = new List <string>();

            System.Reflection.PropertyInfo[] props =
                tt.GetProperties(System.Reflection.BindingFlags.Public |
                                 System.Reflection.BindingFlags.Instance |
                                 System.Reflection.BindingFlags.SetProperty |
                                 System.Reflection.BindingFlags.GetProperty);

            HashSet <uint> hasIdsMap = new HashSet <uint>();

            if (props != null && props.Length > 0)
            {
                for (int i = 0; i < props.Length; ++i)
                {
                    var      prop    = props[i];
                    object[] attrs   = prop.GetCustomAttributes(false);
                    bool     isFound = false;
                    if (attrs != null && attrs.Length > 0)
                    {
                        for (int j = 0; j < attrs.Length; ++j)
                        {
                            ConfigIdAttribute attr = attrs[j] as ConfigIdAttribute;
                            if (attr != null)
                            {
                                if (hasIdsMap.Contains(attr.ID))
                                {
                                    UnityEngine.Debug.LogErrorFormat("typeName: {0}=>attrId {1:D} has exists~~!!", tt.Name, attr.ID);
                                }
                                else
                                {
                                    hasIdsMap.Add(attr.ID);
                                }
                                isFound = true;
                                break;
                            }
                        }
                    }
                    if (!isFound && prop.CanRead && prop.CanWrite)
                    {
                        fieldAndPropNamesNoConfigId.Add(prop.Name);
                    }
                }
            }

            FieldInfo[] fields = tt.GetFields(BindingFlags.Public | BindingFlags.Instance);
            if (fields != null && fields.Length > 0)
            {
                for (int i = 0; i < fields.Length; ++i)
                {
                    var field = fields[i];
                    if (field == null)
                    {
                        continue;
                    }
                    fieldAndPropNamesNoConfigId.Add(field.Name);
                }
            }

            if (fieldAndPropNamesNoConfigId.Count > 0)
            {
                for (int i = 0; i < fieldAndPropNamesNoConfigId.Count; ++i)
                {
                    string fieldName = fieldAndPropNamesNoConfigId[i];
                    if (string.IsNullOrEmpty(fieldName))
                    {
                        continue;
                    }
                    if (str.IndexOf(fieldName) >= 0)
                    {
                        UnityEngine.Debug.LogErrorFormat("typeName: {0}=>【{1}】 is no ConfigId or no Property~~~~!!!!", tt.Name, fieldName);
                    }
                }
            }

            // 检查那些设置了ConfigId,但表里没有的,可以删除
            fieldAndPropNamesNoConfigId.Clear();
            if (props != null && props.Length > 0)
            {
                for (int i = 0; i < props.Length; ++i)
                {
                    var      prop    = props[i];
                    object[] attrs   = prop.GetCustomAttributes(false);
                    bool     isFound = false;
                    if (attrs != null && attrs.Length > 0)
                    {
                        for (int j = 0; j < attrs.Length; ++j)
                        {
                            ConfigIdAttribute attr = attrs[j] as ConfigIdAttribute;
                            if (attr != null)
                            {
                                isFound = true;
                                break;
                            }
                        }
                    }
                    if (isFound && prop.CanRead && prop.CanWrite)
                    {
                        fieldAndPropNamesNoConfigId.Add(prop.Name);
                    }
                }

                if (fieldAndPropNamesNoConfigId.Count > 0)
                {
                    for (int i = 0; i < fieldAndPropNamesNoConfigId.Count; ++i)
                    {
                        string fieldName = fieldAndPropNamesNoConfigId[i];
                        if (string.IsNullOrEmpty(fieldName))
                        {
                            if (str.IndexOf(fieldName) < 0)
                            {
                                UnityEngine.Debug.LogErrorFormat("typeName: {0}=>【{1}】 is can delete~~~~!!!!", tt.Name, fieldName);
                            }
                        }
                    }
                }
            }
        }