Exemple #1
0
        /// <summary>
        /// 反射获取类型的类型成员信息
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private static IEnumerable <TypeSerlizaMemberInfo> GetPacketMemberInfos(Type type)
        {
            var field = type.GetFields();
            var pros  = type.GetProperties();

            List <TypeSerlizaMemberInfo> _listMember = new List <TypeSerlizaMemberInfo>();

            foreach (var r in field)
            {
                if (!r.IsCanSerializeProperty())
                {
                    continue;
                }
                _listMember.Add(new TypeSerlizaMemberInfo()
                {
                    Attribute = r.GetMemberSerializeAttr(),
                    Member    = r
                });
            }
            foreach (var r in pros)
            {
                if (!r.IsCanSerializeProperty())
                {
                    continue;
                }
                if (!r.CanRead)
                {
                    continue;
                }
                if (!r.CanWrite)
                {
                    continue;
                }
                _listMember.Add(new TypeSerlizaMemberInfo()
                {
                    Attribute = r.GetMemberSerializeAttr(),
                    Member    = r
                });
            }


            //获取一个属性在继承链条中的继承深度
            //var shendu = GetPacketMemberInfosJCSD(r,)

            var    _serializerList       = _listMember.OrderBy(p => p.Attribute.Order);
            string befindex              = "";
            TypeSerlizaMemberInfo before = null;

            foreach (var cur in _serializerList)
            {
                if (cur.Attribute.Order == befindex)
                {
                    throw Error.RepeatOrder(typeof(T).FullName, before, cur);
                }
                befindex = cur.Attribute.Order;
                before   = cur;
            }

            return(_serializerList);
        }
Exemple #2
0
 internal static Exception RepeatOrder(
     string serializeTName
     , DynmaicType.TypeSerlizaMemberInfo before
     , DynmaicType.TypeSerlizaMemberInfo cur)
 {
     return(new System.Exception(string.Format("类型: {0}  包含相同成员ID: {1}  字段1: {2}  ,字段2: {3}"
                                               , serializeTName
                                               , before.Attribute.Order,
                                               before.Member.ToString(),
                                               cur.Member.ToString()
                                               )));
 }