我在哪里可以找到MvcTextTemplateHost的API规范?

时间:2011-05-09 15:12:44

标签: asp.net-mvc-3 t4

我正在尝试使用自定义T4模板将新控制器添加到MVC 3项目中。我有自己的模板,正如Scott Hanselman在http://www.hanselman.com/blog/ModifyingTheDefaultCodeGenerationscaffoldingTemplatesInASPNETMVC.aspx上写的那样,但我有兴趣在 MvcTextTemplateHost 类中挖掘更多,看看它提供了什么,所以我们可以自定义一下更多我们的控制器,看看它如何与“添加控制器...”对话框进行交互。

但是我找不到(在谷歌搜索之后,当然......)对这个类的引用,也没有MSDN或者任何其他MS站点......任何想法?

谢谢, 塞吉

5 个答案:

答案 0 :(得分:9)

答案 1 :(得分:5)

public bool AddActionMethods { get; set; }
internal ProjectItem AreaFolder { get; set; }
public string AreaName { get; set; }
public List<string> AssemblyPath { get; set; }
public bool AutoEventWireup { get; set; }
public List<string> ContentPlaceHolderIDs { get; set; }
public Type ContextType { get; set; }
public string ControllerName { get; set; }
public string ControllerRootName { get; set; }
public string EntitySetName { get; set; }
public CompilerErrorCollection Errors { get; set; }
[Dynamic]
public object ExtendedProperties { [return: Dynamic] get; }
public Encoding FileEncoding { get; set; }
public string FileExtension { get; set; }
public Version FrameworkVersion { get; set; }
internal AppDomain GenerationAppDomain { get; set; }
public bool IsContentPage { get; set; }
public bool IsPartialView { get; set; }
public string MasterPageFile { get; set; }
IList<string> ITextTemplatingEngineHost.StandardAssemblyReferences { get; }
IList<string> ITextTemplatingEngineHost.StandardImports { get; }
public Type ModelType { get; set; }
public string Namespace { get; set; }
public string OutputFileExtension { get; set; }
public IPluralizer Pluralizer { get; set; }
public string PrimaryContentPlaceHolderID { get; set; }
public PrimaryKey[] PrimaryKeys { get; set; }
public bool ReferenceScriptLibraries { get; set; }
public Dictionary<string, RelatedModel> RelatedProperties { get; set; }
public string TemplateFile { get; set; }
public Type ViewDataType { get; set; }
public string ViewDataTypeName { get; set; }
public string ViewName { get; set; }

答案 2 :(得分:3)

using Microsoft.VisualStudio.Web.Mvc.Scaffolding.BuiltIn;
using Microsoft.VisualStudio.Web.Mvc.UserInterface;
  

C:\的Windows \ Microsoft.NET \组件\ GAC_MSIL \ Microsoft.VisualStudio.TextTemplating.10.0 \ v4.0_10.0.0.0__b03f5f7f11d50a3a \ Microsoft.VisualStudio.TextTemplating.10.0.dll   Microsoft.VisualStudio.TextTemplating.10.0.dll

     

C:\的Windows \ Microsoft.NET \组件\ GAC_MSIL \ Microsoft.VisualStudio.TextTemplating.10.0 \ v4.0_10.0.0.0__b03f5f7f11d50a3a \ Microsoft.VisualStudio.TextTemplating.10.0.dll   Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll

     

C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ Common7 \ IDE   Microsoft.VisualStudio.Web.Mvc.4.0.dll

如果您将这些作为对MVC Web项目的引用添加并将其设置为MVC版本的正确dll(上面的最后一个dll参考)2.0 3.01 0r 4.0(仍然是Beta)

您可以复制T4代码(而不是标签)并在控制器中运行它,这将提供在创建时在MvcTextTemplateHost对象上设置正确属性数据等所需的智能感知和可调试性,并使用它填充它有意义的数据,看看它在做什么(理论上这将是有效的,我希望)

如前所述,在.NET Reflector中打开这些信息将泄露一些信息。我没有查看MVCScaffolding的代码,源代码是在我的todo列表上的codeplex上)。我现在的问题是在VS.NET 2010 T4中运行时,在MvcTextTemplateHost中填充了相关属性以及如何填充。

也可以使用有形T4编辑器进行智能感知。

答案 3 :(得分:1)

反射器将是您的最佳选择。它允许您反编译DLL。您可以直接在http://shop.reflector.net/download下载。

答案 4 :(得分:1)

这是我们最接近的规格,但它已经过时了:http://blogs.msdn.com/b/webdevtools/archive/2009/01/29/t4-templates-a-quick-start-guide-for-asp-net-mvc-developers.aspx

您可以使用反射,或者您可以查看视图模板,尤其是每个文件底部的相同帮助器方法,以查看MvcTextTemplateHost类中可用的大部分内容。