本文整理汇总了C#中MediaTypeFormatterCollection类的典型用法代码示例。如果您正苦于以下问题:C# MediaTypeFormatterCollection类的具体用法?C# MediaTypeFormatterCollection怎么用?C# MediaTypeFormatterCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaTypeFormatterCollection类属于命名空间,在下文中一共展示了MediaTypeFormatterCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetFormatters
private static MediaTypeFormatterCollection GetFormatters(IEnumerable<MediaTypeFormatter> formatters)
{
var mediaTypeFormatters = new MediaTypeFormatterCollection();
foreach(var formatter in formatters)
mediaTypeFormatters.Add(formatter);
return mediaTypeFormatters;
}
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:7,代码来源:DelegateOperationHandlerFactory.cs
示例2: TestWebApi
private static void TestWebApi()
{
Console.WriteLine();
Console.WriteLine("------------------------------------------------------------");
Console.WriteLine("Web API");
Console.WriteLine("------------------------------------------------------------");
var client = new HttpClient {BaseAddress = new Uri("http://localhost:14851/")};
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var mediaTypeFormatterCollection = new MediaTypeFormatterCollection();
ExecuteAction(NumberOfRequestsToSend + " requests to api/item/id", () =>
{
for (int i = 0; i < NumberOfRequestsToSend; i++)
{
var response = client.GetAsync("api/item/" + Guid.NewGuid()).Result;
if (response.IsSuccessStatusCode)
{
var item = response.Content.ReadAsAsync<Item>(mediaTypeFormatterCollection).Result;
if (item == null)
throw new Exception("Item not received.");
//Console.WriteLine("ItemID\t\t{0}\nDescription\t{1}\nModifiedAt\t{2}", item.ItemID, item.Description, item.ModifiedAt);
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
}
});
}
开发者ID:anilmujagic,项目名称:ServiceBenchmark,代码行数:32,代码来源:Program.cs
示例3: Constructor1_SetsDerivedFormatters
public void Constructor1_SetsDerivedFormatters()
{
// force to array to get stable instances
MediaTypeFormatter[] derivedFormatters = HttpTestData.DerivedFormatters.ToArray();
MediaTypeFormatterCollection collection = new MediaTypeFormatterCollection(derivedFormatters);
Assert.True(derivedFormatters.SequenceEqual(collection));
}
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:7,代码来源:MediaTypeFormatterCollectionTests.cs
示例4: ConfigureFormatters
public static void ConfigureFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.XmlFormatter);
JsonSerializerSettings settings = formatters.JsonFormatter.SerializerSettings;
settings.Formatting = Formatting.None;
}
开发者ID:calvin-pietersen,项目名称:ServiceFabricTSDB,代码行数:7,代码来源:FormatterConfig.cs
示例5: Constructor1SetsProperties
public void Constructor1SetsProperties()
{
// All combination of formatters presented to ctor should still set XmlFormatter
foreach (IEnumerable<MediaTypeFormatter> formatterCollection in HttpUnitTestDataSets.AllFormatterCollections)
{
MediaTypeFormatterCollection collection = new MediaTypeFormatterCollection(formatterCollection);
if (collection.OfType<XmlMediaTypeFormatter>().Any())
{
Assert.NotNull(collection.XmlFormatter);
}
else
{
Assert.Null(collection.XmlFormatter);
}
if (collection.OfType<JsonMediaTypeFormatter>().Any())
{
Assert.NotNull(collection.JsonFormatter);
}
else
{
Assert.Null(collection.JsonFormatter);
}
}
}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:25,代码来源:MediaTypeFormatterCollectionTests.cs
示例6: ActionInvokerComponent
public ActionInvokerComponent(AppFunc next, MediaTypeFormatterCollection formatters, IContentNegotiator contentNegotiator, IActionParameterBinder parameterBinder)
{
_next = next;
_formatters = formatters;
_contentNegotiator = contentNegotiator;
_actionParameterBinder = parameterBinder;
}
开发者ID:dovydasvenckus,项目名称:Resttp,代码行数:7,代码来源:ActionInvokerComponent.cs
示例7: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.XmlFormatter);
var json = formatters.JsonFormatter;
json.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
}
开发者ID:agrc,项目名称:api.mapserv.utah.gov,代码行数:7,代码来源:FormatterConfig.cs
示例8: CamelCasePropertyNamesContractResolver
/// <summary>
/// Format json to camel case
/// </summary>
/// <param name="formatters"></param>
public static void CamelCasePropertyNamesContractResolver(MediaTypeFormatterCollection formatters)
{
var jsonFormatter = formatters.JsonFormatter;
var settings = jsonFormatter.SerializerSettings;
//settings.Formatting = Formatting.Indented;
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
开发者ID:tranphuong02,项目名称:meme-app,代码行数:11,代码来源:JsonFormatter.cs
示例9: ItunesRepository
public ItunesRepository()
{
client = new HttpClient();
client.MaxResponseContentBufferSize = 1000000; // 1MB
formatters = new MediaTypeFormatterCollection();
formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/javascript"));
}
开发者ID:pieterderycke,项目名称:CoverFetcher.Net,代码行数:8,代码来源:ItunesRepository.cs
示例10: HttpResponseErrorHandler
internal HttpResponseErrorHandler(IEnumerable<MediaTypeFormatter> formatters, Uri helpUri, bool includeExceptionDetail)
{
Fx.Assert(formatters != null, "The 'formatters' parameter should not be null.");
this.formatters = new MediaTypeFormatterCollection(formatters);
this.helpUri = helpUri;
this.includeExceptionDetail = includeExceptionDetail;
}
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:8,代码来源:HttpResponseErrorHandler.cs
示例11: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
var jsonFormatter = formatters.JsonFormatter;
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
var jsonpFormatter = new JsonpMediaTypeFormatter(jsonFormatter);
formatters.Add(jsonpFormatter);
}
开发者ID:panesofglass,项目名称:WebApiContrib.Formatting.Jsonp,代码行数:8,代码来源:FormatterConfig.cs
示例12: Configure
private static void Configure(MediaTypeFormatterCollection formatters, HttpConfiguration config)
{
var xml = config.Formatters.XmlFormatter;
formatters.Remove(xml);
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
开发者ID:selgstoen,项目名称:QiuzWeb,代码行数:8,代码来源:WebApiConfig.cs
示例13: Constructor
public void Constructor()
{
MediaTypeFormatterCollection collection = new MediaTypeFormatterCollection();
Assert.Equal(3, collection.Count);
Assert.NotNull(collection.XmlFormatter);
Assert.NotNull(collection.JsonFormatter);
Assert.NotNull(collection.FormUrlEncodedFormatter);
}
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:8,代码来源:MediaTypeFormatterCollectionTests.cs
示例14: SetFormatters
private static void SetFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None;
formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
formatters.JsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Include;
}
开发者ID:1aia,项目名称:webapp,代码行数:9,代码来源:WebApiConfig.cs
示例15: MultipartMediaTypeFormatter
public MultipartMediaTypeFormatter([NotNull] MediaTypeFormatterCollection mediaTypeFormatterCollection,
[NotNull] IPropertyHelper propertyHelper)
{
if (mediaTypeFormatterCollection == null) throw new ArgumentNullException(nameof(mediaTypeFormatterCollection));
if (propertyHelper == null) throw new ArgumentNullException(nameof(propertyHelper));
_mediaTypeFormatterCollection = mediaTypeFormatterCollection;
_propertyHelper = propertyHelper;
SupportedMediaTypes.Add(new MediaTypeHeaderValue("multipart/form-data"));
}
开发者ID:riberk,项目名称:Rib.Common,代码行数:9,代码来源:MultipartMediaTypeFormatter.cs
示例16: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.JsonFormatter);
formatters.Insert(0, new JsonpMediaTypeFormatter {
SerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
}
});
}
开发者ID:ntheile,项目名称:CrossFront-Backend,代码行数:9,代码来源:FormatterConfig.cs
示例17: MediaTypeFormatters
/// <summary>
/// Internal constructor used to build collection of available MediaTypeFormatters
/// </summary>
protected MediaTypeFormatters()
{
formatters = new MediaTypeFormatterCollection();
IMediaTypeFormatterFactory jsonFactory = new JsonFormatterFactory();
formatters.Add(jsonFactory.Formatter());
IMediaTypeFormatterFactory xmlFactory = new XmlFormatterFactory();
formatters.Add(xmlFactory.Formatter());
}
开发者ID:petruta-enciu,项目名称:WeatherAPIApplication,代码行数:12,代码来源:MediaTypeFormatters.cs
示例18: ResttpConfiguration
public ResttpConfiguration(Assembly controllersAssembly)
{
HttpRoutes = new HttpRouteList();
ControllersAssembly = controllersAssembly;
Formatters = new MediaTypeFormatterCollection();
//Formatters.Remove(Formatters.First(f=>f is FormUrlEncodedMediaTypeFormatter));
ContentNegotiator = new ContentNegotiation.ContentNegotiator();
ActionParameterBinder = new Resttp.ActionInvoker.ActionParameterBinder();
}
开发者ID:dovydasvenckus,项目名称:Resttp,代码行数:9,代码来源:ResttpConfiguration.cs
示例19: GetRequestMessage
/// <summary>Construct an HTTP request message.</summary>
/// <param name="method">The HTTP method.</param>
/// <param name="resource">The URI to send the request to.</param>
/// <param name="formatters">The formatters used for serializing and deserializing message bodies.</param>
public virtual HttpRequestMessage GetRequestMessage(HttpMethod method, Uri resource, MediaTypeFormatterCollection formatters)
{
HttpRequestMessage request = new HttpRequestMessage(method, resource);
// add default headers
request.Headers.Add("user-agent", "FluentHttpClient/0.4 (+http://github.com/Pathoschild/Pathoschild.FluentHttpClient)");
request.Headers.Add("accept", formatters.SelectMany(p => p.SupportedMediaTypes).Select(p => p.MediaType));
return request;
}
开发者ID:amixa,项目名称:FluentHttpClient,代码行数:14,代码来源:Factory.cs
示例20: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
// Remove xml formatter (at least for the moment)
formatters.Remove(formatters.XmlFormatter);
// Json formatter
//formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
//formatters.JsonFormatter.Indent = true; ?
//formatters.JsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter());
//formatters.JsonFormatter.MaxDepth = 1;
//formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}
开发者ID:gitter-badger,项目名称:WealthEconomy,代码行数:12,代码来源:FormatterConfig.cs
注:本文中的MediaTypeFormatterCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论