Пример #1
0
 public static object getObject(FieldInfo fi, string src)
 {
     if (ReflecTools.equals(fi, typeof(string)))
     {
         return(StringTools.unescape(src));
     }
     if (ReflecTools.equals(fi, typeof(int)))
     {
         return(int.Parse(src));
     }
     if (ReflecTools.equals(fi, typeof(long)))
     {
         return(long.Parse(src));
     }
     if (ReflecTools.equals(fi, typeof(bool)))
     {
         return(StringTools.toFlag(src));
     }
     if (ReflecTools.equalsOrBase(fi, typeof(Serializable)))
     {
         object dest = fi.FieldType.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
         deserialize(dest, StringTools.decodeLines(src));
         return(dest);
     }
     throw new Exception("そんなタイプ知りません:" + fi);
 }
Пример #2
0
        public static void deserialize(object dest, string[] src)
        {
            for (int index = 0; index < src.Length; index += 2)
            {
                FieldInfo fi    = ReflecTools.getField(dest, src[index]);
                string    value = src[index + 1];

                if (value == "null")
                {
                    value = null;
                }
                else
                {
                    value = value.Substring(1);
                }

                ReflecTools.setValue(fi, dest, getObject(fi, value));
            }
        }
Пример #3
0
 public static object getObject(FieldInfo fi, string src)
 {
     if (ReflecTools.equals(fi, typeof(string)))
     {
         return(StringTools.unescape(src));
     }
     if (ReflecTools.equals(fi, typeof(int)))
     {
         return(int.Parse(src));
     }
     if (ReflecTools.equals(fi, typeof(long)))
     {
         return(long.Parse(src));
     }
     if (ReflecTools.equals(fi, typeof(bool)))
     {
         return(StringTools.toFlag(src));
     }
     throw new Exception("そんなタイプ知りません:" + fi);
 }
Пример #4
0
 public static string getString(FieldInfo fi, object src)
 {
     if (ReflecTools.equals(fi, typeof(string)))
     {
         return(StringTools.escape((string)src));
     }
     if (ReflecTools.equals(fi, typeof(int)))
     {
         return("" + (int)src);
     }
     if (ReflecTools.equals(fi, typeof(long)))
     {
         return("" + (long)src);
     }
     if (ReflecTools.equals(fi, typeof(bool)))
     {
         return(StringTools.toString((bool)src));
     }
     throw new Exception("そんなタイプ知りません:" + fi);
 }
Пример #5
0
        public static string[] serialize(object src)
        {
            List <string> dest = new List <string>();

            foreach (FieldInfo fi in ReflecTools.getFields(src))
            {
                object value = ReflecTools.getValue(fi, src);

                dest.Add(fi.Name);

                if (value == null)
                {
                    dest.Add("null");
                }
                else
                {
                    dest.Add("=" + getString(fi, value));
                }
            }
            return(dest.ToArray());
        }