Пример #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
        }
Пример #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");
        }
Пример #3
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);
            }
        }
Пример #4
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++}]");
            }
        }
Пример #5
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++;
            }
        }
Пример #6
0
 public void Write(object obj, IWriteFormatContext <TWriter> context)
 {
     WriterMethods[obj.GetType()](context.Writer, obj);
 }
Пример #7
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
            var type = (Type)obj;

            context.Write(SerializeType(type), TypeNamePath);
        }
Пример #8
0
 public void Write(object obj, IWriteFormatContext <T> context)
 {
     context.Write(((string)obj).ToCharArray(), "CharArray");
 }
Пример #9
0
        public void Write(object obj, IWriteFormatContext <T> context)
        {
            var guid = (Guid)obj;

            context.Write(guid.ToByteArray(), BytesPath);
        }
Пример #10
0
        public void Write(object obj, IWriteFormatContext <TWriter> context)
        {
            var writeable = (ISeccsWriteable <TWriter>)obj;

            writeable.Write(context.Writer);
        }
Пример #11
0
 protected override void Write(T obj, IWriteFormatContext <TWriter> context) => Writer(obj, context);
Пример #12
0
 protected abstract void Write(T obj, IWriteFormatContext <TWriter> context);
Пример #13
0
 void IWriteFormat <TWriter> .Write(object obj, IWriteFormatContext <TWriter> context) => Write((T)obj, context);