public override string Serialize(UON.SerializationData data, object o) { int refIndex; if (data.GetReferenceIndex(o, out refIndex) == true) { return("#" + refIndex); } StringBuilder buffer = UONUtility.GetBuffer(); IList array = o as IList; data.workingType = UONUtility.GetArraySubType(data.workingType); buffer.Append('['); foreach (object element in array) { string raw = data.ToUON(element); if (string.IsNullOrEmpty(raw) == false) { if (buffer.Length > 1) { buffer.Append(','); } buffer.Append(raw); } } buffer.Append(']'); return(UONUtility.ReturnBuffer(buffer)); }
public override string Serialize(UON.SerializationData data, object o) { int refIndex; if (data.GetReferenceIndex(o, out refIndex) == true) { return("#" + refIndex); } StringBuilder buffer = UONUtility.GetBuffer(); FieldInfo[] fields; IUONSerialization serializationInterface = o as IUONSerialization; if (serializationInterface != null) { serializationInterface.OnSerializing(); } if (this.typesFields.TryGetValue(data.workingType, out fields) == false) { fields = UONUtility.GetFieldsHierarchyOrdered(data.workingType, typeof(object), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).ToArray(); } buffer.Append('{'); foreach (FieldInfo field in fields) { #if NETFX_CORE if (field.IsDefined(typeof(NonSerializedAttribute)) == false) #else if (field.IsNotSerialized == false) #endif { string raw = data.ToUON(field.GetValue(o)); if (string.IsNullOrEmpty(raw) == false) { if (buffer.Length > 1) { buffer.Append(','); } buffer.Append('"'); buffer.Append(field.Name); buffer.Append("\":"); buffer.Append(raw); } } } buffer.Append('}'); return(UONUtility.ReturnBuffer(buffer)); }