Skip to content
Browse files

Remove MediaTypeFormatterCollection.Find() methods.

They were not being used and they did not take into account whether a formatters supported a particular type.
  • Loading branch information...
1 parent a867b46 commit 111ce90b334563f57f066692c407a99f2984a772 @marcind marcind committed Apr 4, 2012
View
16 src/System.Net.Http.Formatting/Formatting/MediaTypeFormatterCollection.cs
@@ -60,22 +60,6 @@ public FormUrlEncodedMediaTypeFormatter FormUrlEncodedFormatter
get { return Items.OfType<FormUrlEncodedMediaTypeFormatter>().FirstOrDefault(); }
}
- public MediaTypeFormatter Find(string mediaType)
- {
- MediaTypeHeaderValue val = MediaTypeHeaderValue.Parse(mediaType);
- return Find(val);
- }
-
- /// <summary>
- /// Find a formatter in this collection that matches the requested media type.
- /// </summary>
- /// <returns>Returns a formatter or null if not found.</returns>
- public MediaTypeFormatter Find(MediaTypeHeaderValue mediaType)
- {
- MediaTypeFormatter formatter = Items.FirstOrDefault(f => f.SupportedMediaTypes.Any(mt => mt.IsSubsetOf(mediaType)));
- return formatter;
- }
-
/// <summary>
/// Helper to search a collection for a formatter that can read the .NET type in the given mediaType.
/// </summary>
View
5 test/System.Web.Http.Integration.Test/ModelBinding/BodyBindingTests.cs
@@ -1,6 +1,7 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
+using System.Net.Http.Headers;
using System.Text;
using Xunit;
using Xunit.Extensions;
@@ -70,7 +71,7 @@ public void Body_Binds_ComplexType_Type_Key_Value_Read(string action, string med
Quantity = 1,
Customer = new ModelBindCustomer { Name = "Fred" }
};
- var formatter = new MediaTypeFormatterCollection().Find(mediaType);
+ var formatter = new MediaTypeFormatterCollection().FindWriter(typeof(ModelBindOrder), new MediaTypeHeaderValue(mediaType));
HttpRequestMessage request = new HttpRequestMessage
{
Content = new ObjectContent<ModelBindOrder>(expectedItem, formatter),
@@ -100,7 +101,7 @@ public void Body_Binds_ComplexType_Type_Whole_Body_Read(string action, string me
Quantity = 1,
Customer = new ModelBindCustomer { Name = "Fred" }
};
- var formatter = new MediaTypeFormatterCollection().Find(mediaType);
+ var formatter = new MediaTypeFormatterCollection().FindWriter(typeof(ModelBindOrder), new MediaTypeHeaderValue(mediaType));
HttpRequestMessage request = new HttpRequestMessage
{
Content = new ObjectContent<ModelBindOrder>(expectedItem, formatter),
View
3 test/System.Web.Http.Integration.Test/ModelBinding/HttpContentBindingTests.cs
@@ -1,6 +1,7 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
+using System.Net.Http.Headers;
using System.Web.Http.SelfHost;
using Xunit;
using Xunit.Extensions;
@@ -30,7 +31,7 @@ public void Dispose()
public void Action_Directly_Reads_HttpRequestMessage(string mediaType)
{
Order order = new Order() { OrderId = "99", OrderValue = 100.0 };
- var formatter = new MediaTypeFormatterCollection().Find(mediaType);
+ var formatter = new MediaTypeFormatterCollection().FindWriter(typeof(Order), new MediaTypeHeaderValue(mediaType));
HttpRequestMessage request = new HttpRequestMessage()
{
Content = new ObjectContent<Order>(order, formatter, mediaType),

0 comments on commit 111ce90

Please sign in to comment.
Something went wrong with that request. Please try again.