我正在尝试将带有此属性 setter 的代码移植到 .net 核心。在这种情况下,我得到了一个我没想到的错误。为什么?有什么不同?
/// <remarks>This uses the native .NET datatype, rather than the FHIR equivalent</remarks>
[NotMapped]
[IgnoreDataMemberAttribute]
public Hl7.Fhir.Model.RemittanceOutcome? Outcome
{
get { return OutcomeElement != null ? OutcomeElement.Value : null; }
set
{
if(value == null) // CS00019
OutcomeElement = null;
else
OutcomeElement = new Code<Hl7.Fhir.Model.RemittanceOutcome>(value);
OnPropertyChanged("Outcome");
}
}
错误在 Enum?
可选类型的 setter 中:
CS0019 Operator '==' cannot be applied to operands of type
'RemittanceOutcome?' and '<null>'
RemittanceOutcome 类型是public enum RemittanceOutcome
。对于可选的枚举,它变得不可能还是现在的实现有所不同?我是否遇到了 ASP.net core 1.0.0 rtm 中的编译器错误?
这是在带有 project.json 的 .net 核心库中,如下所示:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1",
"System.ComponentModel.Annotations": "4.1.0",
"System.ComponentModel.Primitives": "4.1.0",
"System.Diagnostics.Contracts": "4.0.1",
"System.Net.Requests": "4.0.11"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"buildOptions": {
"define": [],
"nowarn": [ "CS3016" ]
}
}
将此代码移植到 dnxcore50(aspnet core 1.0.0 rtm)还有其他一些惊喜,但这个似乎足以让初学者咀嚼。
示例项目:https://github.com/wpostma/fhir-net-api - 分支 dnxcore50。
最佳答案
我会说你遇到了一个错误。这应该是可行的。要确认你可以尝试
if(value.HasValue)
相反,看看它是否有效?
关于C# 可选枚举类型属性 setter 在经典 .net 中编译但不在 .net 核心中编译? (cs0019),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38191166/