本文整理汇总了C#中MediaTypeFormatterCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# MediaTypeFormatterCollection.Remove方法的具体用法?C# MediaTypeFormatterCollection.Remove怎么用?C# MediaTypeFormatterCollection.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaTypeFormatterCollection
的用法示例。
在下文中一共展示了MediaTypeFormatterCollection.Remove方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureFormatters
private static void ConfigureFormatters(MediaTypeFormatterCollection formatters)
{
// Remove unnecessary formatters
MediaTypeFormatter jqueryFormatter = formatters.FirstOrDefault(x => x.GetType() == typeof(JQueryMvcFormUrlEncodedFormatter));
formatters.Remove(formatters.XmlFormatter);
formatters.Remove(formatters.FormUrlEncodedFormatter);
formatters.Remove(jqueryFormatter);
// Suppressing the IRequiredMemberSelector for all formatters
foreach (var formatter in formatters)
{
formatter.RequiredMemberSelector = new SuppressedRequiredMemberSelector();
}
}
示例2: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.XmlFormatter);
formatters.Remove(formatters.JsonFormatter);
var formatter = new JsonMediaTypeFormatter
{
SerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
}
};
formatter.SerializerSettings.Converters.Add(new ExpandoObjectConverter());
formatters.Insert(0, formatter);
}
示例3: ConfigureFormatters
public static void ConfigureFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.XmlFormatter);
JsonSerializerSettings settings = formatters.JsonFormatter.SerializerSettings;
settings.Formatting = Formatting.None;
}
示例4: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.XmlFormatter);
var json = formatters.JsonFormatter;
json.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
}
示例5: 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();
}
示例6: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.JsonFormatter);
formatters.Insert(0, new JsonpMediaTypeFormatter {
SerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
}
});
}
示例7: 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;
}
示例8: 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;
}
示例9: RegisterFormatters
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
var jsonFormatter = formatters.JsonFormatter;
jsonFormatter.SerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects,
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
};
formatters.Remove(formatters.XmlFormatter);
formatters.Insert(0, new JsonMediaTypeFormatter());
}
示例10: RegisterJsonNetMediaTypeFormatter
public static void RegisterJsonNetMediaTypeFormatter(MediaTypeFormatterCollection formatters)
{
formatters.Remove(formatters.OfType<JsonMediaTypeFormatter>().FirstOrDefault());
formatters.Add(new JsonNetMediaTypeFormatter());
}
开发者ID:richardneililagan,项目名称:JSON.net-Web-API-MediaTypeFormatter,代码行数:5,代码来源:MediaTypeFormatterConfig.cs
示例11: Remove_SetsJsonFormatter
public void Remove_SetsJsonFormatter()
{
MediaTypeFormatterCollection collection = new MediaTypeFormatterCollection();
int count = collection.Count;
collection.Remove(collection.JsonFormatter);
Assert.Null(collection.JsonFormatter);
Assert.Equal(count - 1, collection.Count);
}
示例12: RemoveFormatters
private static void RemoveFormatters(MediaTypeFormatterCollection formatterCollection,
IEnumerable<MediaTypeFormatter> formattersToRemove)
{
Contract.Assert(formatterCollection != null);
Contract.Assert(formattersToRemove != null);
// Instantiate a separate array to isolate enumeration from deletions. This code would otherwise throw
// after the first removal.
foreach (MediaTypeFormatter formatter in formattersToRemove.ToArray())
{
formatterCollection.Remove(formatter);
}
}