如何通过接口来描述具有不同访问级别的自动实现的属性?
我正在尝试将此类属性重构为接口。
public class Stuff : IStuff {
public int Number {
get;
protected internal set;
}
}
Visual Studio 2008 重构工具提取以下接口
// Visual Studio 2008's attempt is:
public interface IStuff {
int Number { get; }
}
C# 编译器抱怨错误:(
'Stuff.Number.set' adds an accessor not found in interface member 'IStuff.DataOperations'
这是我遇到的 Visual Studio 生成导致不正确编译情况的代码的少数情况之一。)
是否有直接的解决方案来提取此错误将一个属性放入接口而不在类上进行不同的设置和获取成员/方法?
This class property is what I'm trying to refactor into an interface.
public class Stuff : IStuff {
public int Number {
get;
protected internal set;
}
}
Visual Studio 2008 refactoring tools extract the following interface
// Visual Studio 2008's attempt is:
public interface IStuff {
int Number { get; }
}
The C# compiler complains with the error:
'Stuff.Number.set' adds an accessor not found in interface member 'IStuff.DataOperations'
(This is one of the few circumstances I have run into where Visual Studio generates code that causes an improper compile situation.)
Is there a direct solution to extract this one property into an interface without making distinct set and get members/methods on the class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我测试了以下内容:
并且效果很好。你正确实现了接口吗?
I tested with the following:
and it works just fine. Did you implement the interface correctly?