コード例 #1
0
        public FGReflection(Type type)
        {
            //获取类中所有字段
            FieldInfo[] infos = type.GetFields(_flag);

            FGSerializeInfo sinfo = new FGSerializeInfo();

            for (int i = 0; i < infos.Length; i++)
            {
                //获取所有描述该字段的某个特性
                var attrs = infos[i].GetCustomAttributes(typeof(MemberAttribute), false);

                //var enumerator = attrs.GetEnumerator();
                //while (enumerator.MoveNext())
                //{
                //    enumerator.Current
                //}
                foreach (MemberAttribute attr in attrs)
                {
                    sinfo.info = infos[i];
                    //sinfo.order = attr.Order;
                    sinfo.order        = attr.Length + GetOffsetOrder(infos[i], type);
                    sinfo.length       = attr.Length;
                    sinfo.isLenOfArray = attr.IsLenOfArray;
                    sinfo.arrayName    = attr.ArrayName;
                    fieldList.Add(sinfo);
                    break;
                }
            }

            fieldList.Sort(CompareByOrder);
        }
コード例 #2
0
 private int CompareByOrder(FGSerializeInfo n1, FGSerializeInfo n2)
 {
     if (n1.order == n2.order)
     {
         return(0);
     }
     else
     {
         if (n1.order > n2.order)
         {
             return(1);
         }
         else
         {
             return(-1);
         }
     }
 }