public static string ObjectAsString <T>(T value, bool omitIfNullOrEmpty = true) { var visitor = new HRONWriterVisitor(); VisitObject(value, visitor, omitIfNullOrEmpty); return(visitor.Value); }
public static string SerializeKeyValuePairs(IEnumerable<KeyValuePair<string, object>> keyValuePairs) { if (keyValuePairs == null) { return ""; } var visitor = new HRONWriterVisitor(); SerializeRecursiveDictionaryImpl(keyValuePairs, visitor); return visitor.Value; }
public static string DynamicAsString( HRONObject hronObject ) { if (hronObject == null) { return(""); } var v = new HRONWriterVisitor(); VisitDynamic(hronObject, v); return(v.Value); }
static void SerializeRecursiveDictionaryImpl(IEnumerable<KeyValuePair<string, object>> dictionary, HRONWriterVisitor visitor) { foreach (var kv in dictionary) { var key = kv.Key.ToSubString(); var innerDictionary = kv.Value as IEnumerable<KeyValuePair<string, object>>; if (innerDictionary != null) { visitor.Object_Begin(key); SerializeRecursiveDictionaryImpl( innerDictionary, visitor ); visitor.Object_End(key); } else { visitor.Value_Begin(key); var value = kv.Value; if (value != null) { var formattable = value as IFormattable; var valueAsString = formattable != null ? formattable.ToString("", CultureInfo.InvariantCulture) : value.ToString() ; var lines = valueAsString.ReadLines(); foreach (var line in lines) { visitor.Value_Line(line); } } visitor.Value_End(key); } } }
public static string DynamicAsString( HRONObject hronObject ) { if (hronObject == null) { return ""; } var v = new HRONWriterVisitor(); VisitDynamic(hronObject, v); return v.Value; }