New test.
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / ValueProviderFactoryCollection.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.Collections.Generic;\r
16     using System.Collections.ObjectModel;\r
17     using System.Linq;\r
18 \r
19     public class ValueProviderFactoryCollection : Collection<ValueProviderFactory> {\r
20 \r
21         public ValueProviderFactoryCollection() {\r
22         }\r
23 \r
24         public ValueProviderFactoryCollection(IList<ValueProviderFactory> list)\r
25             : base(list) {\r
26         }\r
27 \r
28         public IValueProvider GetValueProvider(ControllerContext controllerContext) {\r
29             var valueProviders = from factory in this\r
30                                  let valueProvider = factory.GetValueProvider(controllerContext)\r
31                                  where valueProvider != null\r
32                                  select valueProvider;\r
33 \r
34             return new ValueProviderCollection(valueProviders.ToList());\r
35         }\r
36 \r
37 \r
38         protected override void InsertItem(int index, ValueProviderFactory item) {\r
39             if (item == null) {\r
40                 throw new ArgumentNullException("item");\r
41             }\r
42             base.InsertItem(index, item);\r
43         }\r
44 \r
45         protected override void SetItem(int index, ValueProviderFactory item) {\r
46             if (item == null) {\r
47                 throw new ArgumentNullException("item");\r
48             }\r
49             base.SetItem(index, item);\r
50         }\r
51 \r
52     }\r
53 }\r