c# - 如何从另一个属性中获取属性值?
问题描述
我有以下界面:
public interface IReport
{
int ReportId {get; set;}
}
我有一个具有标识列属性的实体:
public int PaymentReportId {get; set;}
我需要PaymentReport
实施IReport
在我的PaymentReport.cs 中,我做了:
public int PaymentReportId {get; set;}
public int ReportId {
get => PaymentReportId;
set {} //no need to ever set this;
}
否则编译器会抱怨没有实现 setter。
有没有更清洁的方法来做到这一点?
解决方案
我从 IReport 的 ReportId 中删除了该集合,然后在类中实现。
public interface IReport
{
int ReportId { get; }
}
public class PaymentReport : IReport
{
public int PaymentReportId { get; set; }
public int ReportId
{
get => PaymentReportId;
}
}
推荐阅读
- angular - 至少有一个文件需要以 Angular 11 反应形式进行验证
- angular - Angular websokcet 和 behaviorSubject 单元测试
- javascript - 材质ui网格将内容方向更改为行
- c++ - 没有以太网连接,但 SSL_write() 返回 true
- python - PyQt5 中的字体无法正确显示
- html - 打开随机生成的画廊的显示图像
- html - wp插件中的模态图像
- machine-learning - Word2Vec 模型中的 windowSize
- nativescript - 在无限滚动的繁重列表负载上崩溃 Nativescript 应用程序
- android - 如何将数据从 BroadcastReceiver 传递到另一个类?