C#可选枚举类型属性设置器在classic.net中编译,但不在.net core中编译?(cs0019)

C#可选枚举类型属性设置器在classic.net中编译,但不在.net core中编译?(cs0019),c#,.net,enums,visual-studio-2015,asp.net-core,C#,.net,Enums,Visual Studio 2015,Asp.net Core,我正在尝试将带有此属性设置程序的代码移植到.net核心。在这种情况下,我遇到了一个意想不到的错误。为什么?有什么不同 /// <remarks>This uses the native .NET datatype, rather than the FHIR equivalent</remarks> [NotMapped] [IgnoreDataMemberAttribute] public Hl7.Fhir.Model.Remittance

我正在尝试将带有此属性设置程序的代码移植到.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");
        }
    }
汇款单输出类型为
公共枚举汇款单输出
。对于一个可选的枚举,它是否变得不可能,或者现在的实现是否有所不同?我在ASP.net core 1.0.0 rtm中遇到编译器错误了吗

这是一个.net核心库,其中包含一个project.json,如下所示:

{
  "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)还有一些其他的惊喜,但这一点似乎足以让初学者深思


示例项目:-分支dnxcore50。

我认为您遇到了一个bug。这应该是可行的。你能试试看吗

if(value.HasValue)

取而代之,看看它是否有效?

作为一个可为空的枚举,检查HasValue是否解决了这个问题

///这使用本机.NET数据类型,而不是FHIR等效数据类型
[未映射]
[IgnoreDataMemberAttribute]
公共Hl7.Fhir.Model.REMENTANCEOUTCOM?结果
{
get{return OutcomeElement!=null?OutcomeElement.值:null;}
设置
{
如果(!value.HasValue)
OutcomeElement=null;
其他的
OutcomeElement=新代码(值);
不动产变更(“结果”);
}
}

听起来很奇怪。出于好奇,如果你说
如果(!value.HasValue).
,它会起作用吗?听起来像是
=
的错误或缺少运算符重载。请在这里填写一个问题()并查看.NET核心开发人员对它的看法。我在GitHub上的corefx问题跟踪器上添加了一个问题。这似乎是更好的方法,但奇怪的是,代码确实在完整的.net项目中编译。这是一个编译器错误还是修复了一个编译器错误?@WarrenP-Wow问真正的问题哈哈。我们不能确定,除非我们和开发人员谈谈。我在问题列表中也找不到它。如果你愿意,你可以在那里报告!我将做一些研究并与他们讨论。我正在移植的代码是由T4模板生成的,所以有了这个特例会让我有些悲伤。
if(value.HasValue)
/// <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.HasValue)
          OutcomeElement = null; 
        else
          OutcomeElement = new Code<Hl7.Fhir.Model.RemittanceOutcome>(value);
        OnPropertyChanged("Outcome");
    }
}