summaryrefslogtreecommitdiff
path: root/mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs
diff options
context:
space:
mode:
authorJo Shields <directhex@apebox.org>2014-02-19 22:12:43 +0000
committerJo Shields <directhex@apebox.org>2014-02-19 22:12:43 +0000
commit9972bf87b4f27d9c8f358ef8414ac1ab957a2f0f (patch)
tree5bb230c1d698659115f918e243c1d4b0aa4c7f51 /mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs
parentd0a215f5626219ff7927f576588a777e5331c7be (diff)
downloadmono-upstream/3.2.8+dfsg.tar.gz
Imported Upstream version 3.2.8+dfsgupstream/3.2.8+dfsg
Diffstat (limited to 'mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs')
-rw-r--r--mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs45
1 files changed, 33 insertions, 12 deletions
diff --git a/mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs b/mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs
index 3772180e52..6337319ea1 100644
--- a/mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs
+++ b/mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs
@@ -4,7 +4,7 @@
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
-// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
+// Copyright (C) 2011, 2014 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -32,6 +32,7 @@ using System.Collections.Generic;
namespace System.Net.Http.Headers
{
delegate bool TryParseDelegate<T> (string value, out T result);
+ delegate bool TryParseListDelegate<T> (string value, int minimalCount, out List<T> result);
abstract class HeaderInfo
{
@@ -89,6 +90,32 @@ namespace System.Net.Http.Headers
}
}
+ class CollectionHeaderTypeInfo<T, U> : HeaderTypeInfo<T, U> where U : class
+ {
+ readonly int minimalCount;
+ TryParseListDelegate<T> parser;
+
+ public CollectionHeaderTypeInfo (string name, TryParseListDelegate<T> parser, HttpHeaderKind headerKind, int minimalCount)
+ : base (name, null, headerKind)
+ {
+ this.parser = parser;
+ this.minimalCount = minimalCount;
+ AllowsMany = true;
+ }
+
+ public override bool TryParse (string value, out object result)
+ {
+ List<T> tresult;
+ if (!parser (value, minimalCount, out tresult)) {
+ result = null;
+ return false;
+ }
+
+ result = tresult;
+ return true;
+ }
+ }
+
public bool AllowsMany;
public readonly HttpHeaderKind HeaderKind;
public readonly string Name;
@@ -104,18 +131,12 @@ namespace System.Net.Http.Headers
return new HeaderTypeInfo<T, object> (name, parser, headerKind);
}
- public static HeaderInfo CreateMulti<T> (string name, TryParseDelegate<T> parser, HttpHeaderKind headerKind) where T : class
- {
- return new HeaderTypeInfo<T, T> (name, parser, headerKind) {
- AllowsMany = true,
- };
- }
-
- public static HeaderInfo CreateMultiList<T> (string name, TryParseDelegate<List<T>> parser, HttpHeaderKind headerKind) where T : class
+ //
+ // Headers with #rule for defining lists of elements or *rule for defining occurences of elements
+ //
+ public static HeaderInfo CreateMulti<T> (string name, TryParseListDelegate<T> elementParser, HttpHeaderKind headerKind, int minimalCount = 1) where T : class
{
- return new HeaderTypeInfo<List<T>, T> (name, parser, headerKind) {
- AllowsMany = true,
- };
+ return new CollectionHeaderTypeInfo<T, T> (name, elementParser, headerKind, minimalCount);
}
public object CreateCollection (HttpHeaders headers)