Ejemplo n.º 1
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
#if NETSTANDARD2_1 || NETCOREAPP
            var tuple = (ITuple)obj;

            context.Write(tuple.Length, "Length");

            for (int i = 0; i < tuple.Length; i++)
            {
                context.Write(tuple[i], $"Item{i + 1}");
            }
#else
            Type t         = obj.GetType();
            int  itemCount = t.GetGenericArguments().Length;

            context.Write(itemCount, "Length");

            for (int i = 1; i < itemCount + 1; i++)
            {
                var item = t.GetField($"Item{i}");

                context.Write(item.GetValue(obj), $"Item{i}");
            }
#endif
        }
Ejemplo n.º 2
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
            Type t = obj.GetType();

            var key   = t.GetProperty("Key").GetValue(obj);
            var value = t.GetProperty("Value").GetValue(obj);

            context.Write(key, "Key");
            context.Write(value, "Value");
        }
Ejemplo n.º 3
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
            var l = (IList)obj;

            context.Write(l.Count, "Count");

            int i = 0;

            foreach (var item in l)
            {
                context.Write(item, $"[{i++}]");
            }
        }
Ejemplo n.º 4
0
        public void Write(object obj, IWriteFormatContext <TWriter> context)
        {
            var dic = (IDictionary)obj;

            context.Write(dic.Count, "Count");

            int i = 0;

            foreach (var key in dic.Keys)
            {
                context.Write(key, $"[{i}].Key");
                context.Write(dic[key], $"[{i}].Value");

                i++;
            }
        }
Ejemplo n.º 5
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
            Type t = obj.GetType();

            foreach (var member in GetMembers(t))
            {
                var getter = ReflectionUtils.MemberGetter(t, member);

                context.Write(getter(obj), member.Name);
            }
        }
Ejemplo n.º 6
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
            var type = (Type)obj;

            context.Write(SerializeType(type), TypeNamePath);
        }
Ejemplo n.º 7
0
 public void Write(object obj, IWriteFormatContext <T> context)
 {
     context.Write(((string)obj).ToCharArray(), "CharArray");
 }
Ejemplo n.º 8
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
            var guid = (Guid)obj;

            context.Write(guid.ToByteArray(), BytesPath);
        }