简体   繁体   English

对Url.Content扩展的智能感知

[英]intellisense on extension of Url.Content

When using MVC Razor you often write @Url.Content("~/images/someimage.png") and you get intellisense on that string - it somehow knows that it's a path. 使用MVC Razor时,您通常会编写@ Url.Content(“〜/ images / someimage.png”)并在该字符串上得到intellisense-它以某种方式知道这是一条路径。

I created an extension method for Url.Content() but it doesn't get intellisense when typing the path parameter. 我为Url.Content()创建了一个扩展方法,但是在输入path参数时它不会得到智能提示。

Does anyone know if there is some kind of attribute you can put on parameters, or is there a better way (an override?) I can cut in and change the default Url.Content's behaviour? 有谁知道您可以在参数上添加某种属性,还是有更好的方法(覆盖?),我可以插入并更改默认的Url.Content的行为?

    public static string ContentExtended(this UrlHelper urlHelper, string contentPath)
    {
        string result = urlHelper.Content(contentPath);

        // do stuff here to remove application folder name on godaddy hosting

        return result;
    }

EDIT: I use resharper, and just realised this might be a resharper-specific feature that regular VS users don't actually have. 编辑:我使用resharper,只是意识到这可能是常规VS用户实际上没有的,特定于resharper的功能。 I disabled Resharper intellisense, and just had the regular VS intellisense on, and the path specific auto-complete didn't work. 我禁用了Resharper intellisense,仅启用了常规的VS intellisense,并且特定于路径的自动完成功能不起作用。 So this is a resharper feature, not a programming problem 因此,这是一个共享工具,而不是编程问题

Matt, it's really ReSharper's feature. 马特,这确实是ReSharper的功能。 You need to mark contentPath parameter with PathReferenceAttribute attribute. 您需要使用PathReferenceAttribute属性标记contentPath参数。 You can copy it's implementation to your project from ReSharper → Options → Code Inspection → Code Annotations. 您可以从ReSharper→选项→代码检查→代码注释将其实现复制到项目中。

You'd need to provide XML documentation: 您需要提供XML文档:

/// <summary>
/// Lorem ipsum...
/// </summary>
/// <param name="urlHelper">The helper to provide content to</param>
/// <param name="contentPath">The path to the content</param>

This isn't just for extension methods - it's how you provide documentation (picked up by IntelliSense) for everything. 这不仅仅适用于扩展方法,而是您提供所有内容的文档(由IntelliSense挑选)的方式。

If you're talking about something more than that, in terms of IntelliSense suggesting possible values, that may be an attribute... 如果您谈论的不止是这些,就IntelliSense建议的可能值而言, 可能是一个属性...

尝试使用此http://mvccontrib.codeplex.com/wikipage?title=T4MVC具有静态内容智能功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM