private object ConvertItemToValue(Type targetType, OMCLItem item) { var tags = item.Tags; var sourceType = item.Type; switch (sourceType) { case OMCLItem.OMCLItemType.None: return(ConvertNone(targetType, tags)); case OMCLItem.OMCLItemType.String: return(ConvertString(targetType, tags, item.AsString())); case OMCLItem.OMCLItemType.Int: return(Convert.ChangeType(item.AsInt(), targetType)); case OMCLItem.OMCLItemType.Bool: return(item.AsBool()); case OMCLItem.OMCLItemType.Float: return(Convert.ChangeType(item.AsFloat(), targetType)); case OMCLItem.OMCLItemType.Object: return(ConvertObject(targetType, tags, item.AsObject())); case OMCLItem.OMCLItemType.Array: return(ConvertArray(targetType, tags, item.AsArray())); default: throw new NotImplementedException(); } }
public void Serialize(OMCLItem item) { switch (item.Type) { case OMCLItem.OMCLItemType.Object: Write(item.AsObject()); break; case OMCLItem.OMCLItemType.Array: Write(item.AsArray()); break; case OMCLItem.OMCLItemType.String: Write(item.AsString()); break; case OMCLItem.OMCLItemType.Bool: Write(item.AsBool()); break; case OMCLItem.OMCLItemType.Int: Write(item.AsInt()); break; case OMCLItem.OMCLItemType.Float: Write(item.AsFloat()); break; } _writer.Flush(); _writer.Close(); }
private void WriteValue(OMCLItem item) { var prev = _indentationLevel++; try { foreach (var t in item.Tags) { _writer.Write($"!{t} "); } switch (item.Type) { case OMCLItem.OMCLItemType.Object: Write(item.AsObject()); break; case OMCLItem.OMCLItemType.Array: Write(item.AsArray()); break; case OMCLItem.OMCLItemType.String: var str = item.AsString(); var parts = str.Split('"'); var escaped = string.Join("\" '\"' \"", parts); Write(escaped); break; case OMCLItem.OMCLItemType.Bool: Write(item.AsBool()); break; case OMCLItem.OMCLItemType.Int: Write(item.AsInt()); break; case OMCLItem.OMCLItemType.Float: Write(item.AsFloat()); break; case OMCLItem.OMCLItemType.None: Write(item.AsNone()); break; } } finally { _indentationLevel = prev; } }