From 9972bf87b4f27d9c8f358ef8414ac1ab957a2f0f Mon Sep 17 00:00:00 2001 From: Jo Shields Date: Wed, 19 Feb 2014 22:12:43 +0000 Subject: Imported Upstream version 3.2.8+dfsg --- .../System.Net.Http.Headers/HeaderInfo.cs | 45 ++++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'mcs/class/System.Net.Http/System.Net.Http.Headers/HeaderInfo.cs') 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 // -// 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 (string value, out T result); + delegate bool TryParseListDelegate (string value, int minimalCount, out List result); abstract class HeaderInfo { @@ -89,6 +90,32 @@ namespace System.Net.Http.Headers } } + class CollectionHeaderTypeInfo : HeaderTypeInfo where U : class + { + readonly int minimalCount; + TryParseListDelegate parser; + + public CollectionHeaderTypeInfo (string name, TryParseListDelegate 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 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 (name, parser, headerKind); } - public static HeaderInfo CreateMulti (string name, TryParseDelegate parser, HttpHeaderKind headerKind) where T : class - { - return new HeaderTypeInfo (name, parser, headerKind) { - AllowsMany = true, - }; - } - - public static HeaderInfo CreateMultiList (string name, TryParseDelegate> 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 (string name, TryParseListDelegate elementParser, HttpHeaderKind headerKind, int minimalCount = 1) where T : class { - return new HeaderTypeInfo, T> (name, parser, headerKind) { - AllowsMany = true, - }; + return new CollectionHeaderTypeInfo (name, elementParser, headerKind, minimalCount); } public object CreateCollection (HttpHeaders headers) -- cgit v1.2.3