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 }
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"); }
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++}]"); } }
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++; } }
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); } }
public void Write(object obj, IWriteFormatContext <T> context) { var type = (Type)obj; context.Write(SerializeType(type), TypeNamePath); }
public void Write(object obj, IWriteFormatContext <T> context) { context.Write(((string)obj).ToCharArray(), "CharArray"); }
public void Write(object obj, IWriteFormatContext <T> context) { var guid = (Guid)obj; context.Write(guid.ToByteArray(), BytesPath); }