【发布时间】:2019-06-03 15:26:46
【问题描述】:
我正在尝试通过我的项目并使用相应的 Resharper / Jetbrains 注释来注释我的所有方法,因此当我不小心尝试传递不属于某个地方的东西时,我有一些帮助和一些东西可以打我。
但是,这是我无法理解的。
考虑以下几点:
public interface ITestClass
{
Task<int?> TestMethod([CanBeNull] int? testInput);
}
public class TestClass : ITestClass
{
public async Task<int?> TestMethod(int? testInput)
{
return await Task.FromResult(testInput);
}
}
public class TestConsumer
{
[NotNull]
private readonly ITestClass m_tester;
[NotNull]
private readonly TestClass m_tester2;
public TestConsumer([NotNull] ITestClass tester, [NotNull] TestClass tester2)
{
m_tester = tester;
m_tester2 = tester2;
}
public async Task TestMethod([NotNull] int? testInput)
{
var test1 = await m_tester.TestMethod(testInput);
var test2 = await m_tester2.TestMethod(testInput);
}
}
我重建了它以显示我现在面临的问题。通常,我正在使用依赖注入,并且我希望某些服务的接口(在这种情况下让“ITestClass”成为服务“TestClass”的接口)在我的构造函数中。控制器(参见“TestConsumer”)。
但是,R# / Jetbrains Annotations 显然不喜欢这样。但是,当我尝试使用该接口的实现来代替时 - 没问题。
这真的有点烦人。我现在不想让我的整个代码摇摆不定。显然,这也只是处理等待/异步代码时的一个问题,因为如果我省略了“等待”,这两种情况都适用,但这不是一个选项。
有什么解决办法吗?最后,R# 在实现中的接口中可能缺少什么?方法定义在那里。
编辑:
更多信息:
我在 Visual Studio Enterprise 2017 版本 15.6.1 中运行 Resharper Ultimate 2018.3.1。
【问题讨论】:
-
我们能不能直接贴出代码而不是图片?
-
这不适合我(使用 R# 2016.1.2)所以也许有一个设置可以关闭它?
-
将来,您可能希望编辑原始帖子 - 以免丢失原始帖子中的 cmets 等。
-
@JonathonChase 有人已经这么好心了。谢谢,谁在这里工作:)
标签: c# annotations resharper