2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System.Web.Mvc / System.Web.Mvc / ViewDataDictionary`1.cs
blobd1ed1099f7622c2660d187aabd2059736e19e139
1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * This software is subject to the Microsoft Public License (Ms-PL).
6 * A copy of the license can be found in the license.htm file included
7 * in this distribution.
9 * You must not remove this notice, or any other, from this software.
11 * ***************************************************************************/
13 namespace System.Web.Mvc {
14 using System;
15 using System.Globalization;
16 using System.Web.Mvc.Resources;
18 public class ViewDataDictionary<TModel> : ViewDataDictionary where TModel : class {
19 public ViewDataDictionary() :
20 base() {
23 public ViewDataDictionary(TModel model) :
24 base(model) {
27 public ViewDataDictionary(ViewDataDictionary viewDataDictionary) :
28 base(viewDataDictionary) {
31 public new TModel Model {
32 get {
33 return (TModel)base.Model;
35 set {
36 SetModel(value);
40 protected override void SetModel(object value) {
41 TModel model = value as TModel;
43 // If there was a value but the cast failed, throw an exception
44 if ((value != null) && (model == null)) {
45 throw new InvalidOperationException(
46 String.Format(CultureInfo.CurrentUICulture,
47 MvcResources.ViewDataDictionary_WrongTModelType, value.GetType(), typeof(TModel)));
50 base.SetModel(value);