/// <summary> /// Write Any object to the given writer. /// </summary> /// <param name="writer">The writer.</param> public void Write(IOpenApiWriter writer) { if (writer == null) { throw Error.ArgumentNull("writer"); } // { for json, empty for YAML writer.WriteStartObject(); foreach (var item in this) { writer.WritePropertyName(item.Key); IOpenApiWritable writerElement = item.Value as IOpenApiWritable; if (writerElement != null) { writerElement.Write(writer); } else { writer.WriteValue(item.Value); } } // } for json, empty for YAML writer.WriteEndObject(); }
private static void WriteValueInternal <T>(this IOpenApiWriter writer, T value) { IOpenApiWritable writableElement = value as IOpenApiWritable; if (writableElement != null) { writableElement.Write(writer); } else { writer.WriteValue(value); } }
internal static string WriteToYaml(this IOpenApiWritable element, Action <IOpenApiWriter, IOpenApiWritable> before = null, Action <IOpenApiWriter, IOpenApiWritable> after = null) { Action <IOpenApiWriter> action = writer => { before?.Invoke(writer, element); element?.Write(writer); after?.Invoke(writer, element); writer?.Flush(); }; return(Write(OpenApiTarget.Yaml, action)); }