我通过resharper的代码检查做了一些代码分析,我得到了下一个警告:
只使用属性“propertyname”的实现
这个警告在我的界面上,如果我谷歌我找到了jetbrains:http://confluence.jetbrains.com/display/ReSharper/Only+implementations+of+property+are+used的页面
那对我一点帮助都没有,因为那样我就没有接口了.
所以我开始测试如何消除这个警告。在折叠虚拟接口和类上:
public interface ITest
{
string Name { get; set; }
}
public class Test: ITest
{
public string Name { get; set; }
}如果我用:
var newTest = new Test();
newTest.Name= "newName";然后就会发出警告。但当我使用下一行时,警告就会消失。
ITest newTest = new Test();
newTest.Name = "newName";我不是一个界面忍者,所以我想知道,这两种方式有什么区别?
谢谢!
发布于 2013-03-28 12:26:11
这就推断出混凝土的类型:
//X is of type X
var x = new X(); 这不是
//X is of type IX
IX x = new X();我猜如果你写的话这个警告还会出现
//X is of type X
X x = new X();以下是否也删除了警告?
public void TestX()
{
//X is of type X
var x = new X();
UseIX(x);
}
public void UseIX(IX interfaceParam)
{
interfaceParam.Foo = 1;
}发布于 2013-03-28 12:25:34
var newTest = newTest ()将newTest类型设置为Test。ITest newTest = newTest ()将newTest的类型设置为ITest。
因此,对于前者,ITest并不是必需的,因为它从未被使用过。
所以,resharper只是说你不需要ITest。你是否同意由你来决定。你需要ITest吗?
https://stackoverflow.com/questions/15681665
复制相似问题