コード例 #1
0
        /// <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();
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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));
        }