private void SerializeObject <T>(ref T obj, uint flags) { if (obj == null) { if (!CreateObject(out var newObj)) { obj = (T)newObj; return; } obj = (T)newObj; } if (obj != null) { Type type = obj.GetType(); if (type == typeof(T)) { FormatterCache <T> .Instance.Serialize(this, ref obj, flags); } else { FormatterCache.Get(type).Serialize(this, ref Unsafe.As <T, object>(ref obj), flags); } } else { FormatterCache <T> .Instance.Serialize(this, ref obj, flags); } }
public virtual void Serialize <T>(ref T val, uint flags) { Type type = typeof(T); if (type.IsPrimitive) { SerializePrimitive(ref val); } else { if (val == null) { SerializeNull(); } else if (type == val.GetType()) { FormatterCache <T> .Instance.Serialize(this, ref val, flags); } else { FormatterCache.Get(val.GetType()).Serialize(this, ref Unsafe.As <T, object>(ref val), flags); } } }