在哪里可以找到DynamicViewDataDictionary的官方文档? [英] Where can I find the official documentation for DynamicViewDataDictionary?

查看:301
本文介绍了在哪里可以找到DynamicViewDataDictionary的官方文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Visual Web Developer调试时, ViewBag 显示为类型 System.Web.Mvc.DynamicViewDataDictionary

When I'm debugging in 'Visual Web Developer' the ViewBag is shown as being of type System.Web.Mvc.DynamicViewDataDictionary.

由于ViewBag是我使用的,我想阅读其类型的文档。

Since the ViewBag is something I'm using I'd like to read the documentation of its type.

用法可以是: / p>

Usage could be:

ViewBag.Message = "whatever";

Google没有发现任何看起来像截至7月18日的官方文档, 2011年。

Google gives few results and I didn't find anything that looked like official documentation as of July 18, 2011.

我只找到有关 ViewDataDictionary-type ViewBag变量本身当前几乎为空,仅包含以下内容:

I only found documentation about the ViewDataDictionary-type and the ViewBag variable itself which is currently nearly empty, containing only the following:

Gets the dynamic view data dictionary.

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)
Syntax C#

public Object ViewBag { get; }

Property Value
Type: System.Object
The dynamic view data dictionary.

See Also
Reference
ControllerBase Class
System.Web.Mvc Namespace

是否存在DynamicViewDataDictionary的官方文档?

如果没有,是暂时的,因为它是新的或者是sth。由于某些原因不会被记录在案?

推荐答案

感谢Frédéric和Hector两个答案都非常有帮助!

Thanks to Frédéric and Hector both answers were very helpful!

背景信息

虽然DynamicViewDataDictionary是 internal 密封可以说,没有记录它是有道理的,但是由于我们使用ViewBag它是DynamicViewDataDictionary类型,读取有关其类型的文档也是有道理的。

ViewBag本身目前基本上是 undocumented ,所以当我们调查源代码(如下所示)时,按照Hector的建议,我们发现DynamicViewDataDictionary inhe来自DynamicObject的rits,但对其基类增加了一点。

While DynamicViewDataDictionary is internal and sealed one can argue that it makes sense that it's not documented, but since we are using the ViewBag which is of type "DynamicViewDataDictionary", reading documentation about its type makes sense as well.
The ViewBag itself is currently basically undocumented, so when we investigate the source code (quoted below), as suggested by Hector, we find that DynamicViewDataDictionary inherits from DynamicObject but adds little to its base class.

DynamicObject的文档


此类必须从...继承; 您无法直接实例化。

现在所有这一切都有意义:

DynamicViewDataDictionary根本没有记录,ViewBag的文档几乎是空的,但是我们可以从源代码中了解到,通过阅读关于被广泛记录的动态对象

Now all of this makes sense:
DynamicViewDataDictionary isn't documented at all, the ViewBag's documentation is nearly empty but as we can learn from the source code we can get most of the info about the ViewBag's behavior by reading about DynamicObject which is extensively documented.

所以我们得到的所有信息主要来自 DynamicObject的文档以及DynamicViewDataDictionary源代码中的一些附加信息。

So we get all the information we want mostly from the documentation of DynamicObject and some additional info from DynamicViewDataDictionary's source code.

以下是从这里下载的DynamicViewDataDictionary.cs的完整内容。 ('mvc3-rtm-mspl.zip'文件)

The following is the complete content of DynamicViewDataDictionary.cs which I downloaded from here. (the 'mvc3-rtm-mspl.zip'-file)

/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 *
 * This software is subject to the Microsoft Public License (Ms-PL). 
 * A copy of the license can be found in the license.htm file included 
 * in this distribution.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * ***************************************************************************/

namespace System.Web.Mvc {
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Dynamic;

    internal sealed class DynamicViewDataDictionary : DynamicObject {
        private readonly Func<ViewDataDictionary> _viewDataThunk;

        public DynamicViewDataDictionary(Func<ViewDataDictionary> viewDataThunk) {
            _viewDataThunk = viewDataThunk;
        }

        private ViewDataDictionary ViewData {
            get {
                ViewDataDictionary viewData = _viewDataThunk();
                Debug.Assert(viewData != null);
                return viewData;
            }
        }

        // Implementing this function improves the debugging experience as it provides the debugger with the list of all
        // the properties currently defined on the object
        public override IEnumerable<string> GetDynamicMemberNames() {
            return ViewData.Keys;
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result) {
            result = ViewData[binder.Name];
            // since ViewDataDictionary always returns a result even if the key does not exist, always return true
            return true;
        }

        public override bool TrySetMember(SetMemberBinder binder, object value) {
            ViewData[binder.Name] = value;
            // you can always set a key in the dictionary so return true
            return true;
        }
    }
}

这篇关于在哪里可以找到DynamicViewDataDictionary的官方文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆