Пример #1
0
 public YamlInputFormatter(YamlFormatterOptions YamlFormatterOptions)
 {
     _options = YamlFormatterOptions ?? throw new ArgumentNullException(nameof(YamlFormatterOptions));
     foreach (var contentType in YamlFormatterOptions.SupportedContentTypes)
     {
         SupportedMediaTypes.Add(new MediaTypeHeaderValue(contentType));
     }
     _deserializer = new Deserializer();
 }
 public YamlOutputFormatter(YamlFormatterOptions YamlFormatterOptions)
 {
     ContentType = "application/x-yaml";
     _options    = YamlFormatterOptions ?? throw new ArgumentNullException(nameof(YamlFormatterOptions));
     foreach (var contentType in YamlFormatterOptions.SupportedContentTypes)
     {
         SupportedMediaTypes.Add(new MediaTypeHeaderValue(contentType));
     }
     _serializer = new Serializer();
 }
        public static IMvcCoreBuilder AddYamlFormatters(this IMvcCoreBuilder builder, Action <YamlFormatterOptions> YamlFormatterOptionsConfiguration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var YamlFormatterOptions = new YamlFormatterOptions();

            YamlFormatterOptionsConfiguration?.Invoke(YamlFormatterOptions);

            foreach (var extension in YamlFormatterOptions.SupportedExtensions)
            {
                foreach (var contentType in YamlFormatterOptions.SupportedContentTypes)
                {
                    builder.AddFormatterMappings(m => m.SetMediaTypeMappingForFormat(extension, new MediaTypeHeaderValue(contentType)));
                }
            }

            builder.AddMvcOptions(options => options.InputFormatters.Add(new YamlInputFormatter(YamlFormatterOptions)));
            builder.AddMvcOptions(options => options.OutputFormatters.Add(new YamlOutputFormatter(YamlFormatterOptions)));

            return(builder);
        }