Implement MachineKey.Protect and MachineKey.Unprotect
[mono.git] / mcs / class / System.Web.Mvc / System.Web.Mvc / ViewDataDictionary`1.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.Globalization;\r
16     using System.Web.Mvc.Resources;\r
17 \r
18     public class ViewDataDictionary<TModel> : ViewDataDictionary where TModel : class {\r
19         public ViewDataDictionary() :\r
20             base() {\r
21         }\r
22 \r
23         public ViewDataDictionary(TModel model) :\r
24             base(model) {\r
25         }\r
26 \r
27         public ViewDataDictionary(ViewDataDictionary viewDataDictionary) :\r
28             base(viewDataDictionary) {\r
29         }\r
30 \r
31         public new TModel Model {\r
32             get {\r
33                 return (TModel)base.Model;\r
34             }\r
35             set {\r
36                 SetModel(value);\r
37             }\r
38         }\r
39 \r
40         protected override void SetModel(object value) {\r
41             TModel model = value as TModel;\r
42 \r
43             // If there was a value but the cast failed, throw an exception\r
44             if ((value != null) && (model == null)) {\r
45                 throw new InvalidOperationException(\r
46                     String.Format(CultureInfo.CurrentUICulture,\r
47                         MvcResources.ViewDataDictionary_WrongTModelType, value.GetType(), typeof(TModel)));\r
48             }\r
49 \r
50             base.SetModel(value);\r
51         }\r
52     }\r
53 }\r