コード例 #1
0
        public static string SerializeArray(object obj)
        {
            Array array = obj as Array;

            if (array == null)
            {
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();

            using (StringWriter writer = new StringWriter(stringBuilder))
            {
                BloxStringSerializer.WriteIntToStringWriter(writer, array.Length);
                for (int i = 0; i < array.Length; i++)
                {
                    string text = BloxStringSerializer.Serialize(array.GetValue(i));
                    BloxStringSerializer.WriteIntToStringWriter(writer, (text != null) ? text.Length : 0);
                }
            }
            return(stringBuilder.ToString());
        }
コード例 #2
0
        public static string SerializeList(object obj)
        {
            IList list = obj as IList;

            if (list == null)
            {
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();

            using (StringWriter stringWriter = new StringWriter(stringBuilder))
            {
                BloxStringSerializer.WriteIntToStringWriter(stringWriter, list.Count);
                for (int i = 0; i < list.Count; i++)
                {
                    string text = BloxStringSerializer.Serialize(list[i]);
                    BloxStringSerializer.WriteIntToStringWriter(stringWriter, (text != null) ? text.Length : 0);
                    stringWriter.Write(text);
                }
            }
            return(stringBuilder.ToString());
        }