以非侵入性方式将 Resharper 代码注释添加到自己的代码中 [英] Adding Resharper code annotation to own code in a non-invasive manner

查看:24
本文介绍了以非侵入性方式将 Resharper 代码注释添加到自己的代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 StringFormatMethod 属性标记我的方法之一,以便 Resharper 语法突出显示它.

I want to flag one of my methods with the StringFormatMethod attribute so Resharper syntax highlights it.

通过引用 JerBrains.Annotations 程序集并添加属性,我能够做到这一点.

I was able to do this by referencing the JerBrains.Annotations assembly and adding the attribute.

但是,我发现这是一种非常具有侵入性的方法.这里并不是每个人都使用 JetBrains,它需要将 .dll 提交到 Subversion,添加依赖项,并用我讨厌的特定 IDE 特定的东西乱扔代码.

However I find this to be a very invasive way to do this. Not everybody here uses JetBrains and it will require committing the .dll to subversion, adding the dependency and littering the code with something that is specific to a particular IDE, which I hate.

我了解了外部注释"功能,但我无法做到.我不确定是我做错了还是解决方案中的项目根本不支持它(即不是编译后的程序集引用).

I read about the "external annotations" feature, but I wasn't able to do it. I'm not sure if I did it wrong or if it's simply not supported for a project inside the solution (i.e not a compiled assembly reference).

那么有没有办法在项目中的方法中添加代码注解,以非侵入的方式?

So is there a way to add a code annotation to a method in the project in a non-invasive way?

P.S 这是方法:

使用系统;

namespace MyLib
{
    public static class Assert
    {
        public static void That(bool condition, string format, params object[] @params)
        {
            if (!condition)
                throw new Exception(string.Format(format, @params));
        }
    }
}

这是内容

C:\Program Files (x86)\JetBrains\ReSharper\v7.1\Bin\ExternalAnnotations\MyLib.xml:

C:\Program Files (x86)\JetBrains\ReSharper\v7.1\Bin\ExternalAnnotations\MyLib.xml:

<assembley name="MyLib">
    <member name="MyLib.Assert.That(System.Boolean,System.String,System.Object[])">
        <attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor">
            <argument>format</argument>
        </attribute>
    </member>
</assembley>

推荐答案

您不必引用程序集来添加注释属性.根据文档,您可以转到ReSharper/Options/Code Annotations,将属性实现复制到剪贴板,并将它们粘贴到您自己的源中,ReSharper 将在其中使用它们.如果您不想在程序集中使用 JetBrains,您甚至可以更改它们所在的命名空间.

You don't have to reference the assembly to add annotation attributes. As per the documentation, you can go to ReSharper/Options/Code Annotations, copy the attribute implementations to the clipboard, and paste them into your own source, where ReSharper will use them. You can even change the namespace they're in if you'd prefer not to have JetBrains in your assembly.

不过,我不知道您是否会为源代码使用外部 (XML) 注释.我的印象是它们仅适用于现有的二进制文件.也就是说,我认为用属性装饰你的源代码对于你自己和其他开发者来说是非常有价值的文档来源.

I don't know whether you'll have any luck using external (XML) annotations for source code, though. I get the impression they're only for existing binaries. That said, I think that decorating your source with attributes is quite valuable as a source of documentation for yourself and other developers.

这篇关于以非侵入性方式将 Resharper 代码注释添加到自己的代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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