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
16 public class ViewDataDictionary<TModel> : ViewDataDictionary {
\r
17 public ViewDataDictionary() :
\r
18 base(default(TModel)) {
\r
21 public ViewDataDictionary(TModel model) :
\r
25 public ViewDataDictionary(ViewDataDictionary viewDataDictionary) :
\r
26 base(viewDataDictionary) {
\r
29 public new TModel Model {
\r
31 return (TModel)base.Model;
\r
38 public override ModelMetadata ModelMetadata {
\r
40 ModelMetadata result = base.ModelMetadata;
\r
41 if (result == null) {
\r
42 result = base.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel));
\r
47 base.ModelMetadata = value;
\r
51 protected override void SetModel(object value) {
\r
52 bool castWillSucceed = TypeHelpers.IsCompatibleObject<TModel>(value);
\r
54 if (castWillSucceed) {
\r
55 base.SetModel((TModel)value);
\r
58 InvalidOperationException exception = (value != null)
\r
59 ? Error.ViewDataDictionary_WrongTModelType(value.GetType(), typeof(TModel))
\r
60 : Error.ViewDataDictionary_ModelCannotBeNull(typeof(TModel));
\r