1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\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
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Globalization;
\r
16 using System.Web.Mvc.Resources;
\r
18 public class ViewDataDictionary<TModel> : ViewDataDictionary where TModel : class {
\r
19 public ViewDataDictionary() :
\r
23 public ViewDataDictionary(TModel model) :
\r
27 public ViewDataDictionary(ViewDataDictionary viewDataDictionary) :
\r
28 base(viewDataDictionary) {
\r
31 public new TModel Model {
\r
33 return (TModel)base.Model;
\r
40 protected override void SetModel(object value) {
\r
41 TModel model = value as TModel;
\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
50 base.SetModel(value);
\r