-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make removing a formatter a 1-liner #2945
Comments
Hi, I'm new to contributing to other projects but would like to give this a shot. Were you thinking something like this? namespace Microsoft.AspNet.Mvc.Core.Formatters
{
public class FormatterCollection<TFormatter> : Collection<TFormatter>
{
/// <summary>
/// Removes all formatters of the specified type.
/// </summary>
/// <typeparam name="T">The type to remove.</typeparam>
public void RemoveType<T>() where T : TFormatter
{
var formatters = this.OfType<T>();
foreach (var formatter in formatters)
{
Remove(formatter);
}
}
}
} public MvcOptions()
{
// ...
InputFormatters = new FormatterCollection<IInputFormatter>();
OutputFormatters = new FormatterCollection<IOutputFormatter>();
// ...
}
public FormatterCollection<IInputFormatter> InputFormatters { get; }
public FormatterCollection<IOutputFormatter> OutputFormatters { get; }
// ... Should the |
I'm cool with this. BTW I'm not sure the proposed code will necessarily work: you might have to force |
Great. I'll go ahead and make a pull request later today. @Eilon You are right, it needs to be changed. |
Avoid using LINQ if you can. If you use a |
Why does this matter? This is about making startup code more friendly. |
See code sample here: #2944 (comment)
When we were using descriptors for formatters we had a 1-liner extension method for removing a formatter by-type from the collection. We should add this back by defining custom collection types for input formatters and output formatters.
The text was updated successfully, but these errors were encountered: