我在哪里可以找到DynamicViewDataDictionary正式文件? [英] Where can I find the official documentation for DynamicViewDataDictionary?

查看:266
本文介绍了我在哪里可以找到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.

使用方法可以是:

ViewBag.Message = "whatever";

谷歌给出了一些成果,我没有发现任何疑似的官方文件为2011年7月18日的。

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

我只找到文档中关于的的ViewDataDictionary型和<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.viewbag%28v=vs.98%29.aspx\">the 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官方文档存在吗?结果
如果不是,它只是暂时,因为它是新的或者是某事。不会被记录出于某种原因?

推荐答案

由于弗雷德里克·赫克托两个答案是非常有益的!

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

背景信息

虽然DynamicViewDataDictionary是内部密封人们可以争辩说,它是有道理的,它没有记录,但是由于我们使用的是ViewBag它的类型是DynamicViewDataDictionary,阅读它的类型文档是有道理的为好。结果
该ViewBag本身目前基本上<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.viewbag%28v=vs.98%29.aspx\"相对=nofollow>无证,所以当我们探讨源$ C ​​$ C(以下引用),由赫克托的建议,我们发现,从DynamicViewDataDictionary继承DynamicObject但增加了一点它的基类。

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 的文档:

From the documentation of DynamicObject:

这个类必须从继承; 您不能直接实例化。

This class must be inherited from; you cannot instantiate it directly.

现在这一切是有道理的:结果
DynamicViewDataDictionary是不是在所有的记录中,ViewBag的文档几乎是空的,但是,我们可以从源$ C ​​$ C,我们可以得到最为牵挂的ViewBag行为的信息通过阅读有关的
DynamicObject这是广泛记载

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源$ C ​​$ C一些额外的信息。

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天全站免登陆