dotnet/runtime

C# compiler should not report CS0649 when the fields in question are marked with [DataMember] attribute

開放

#45,207 建立於 2020年11月25日

 (3 則留言) (0 個反應) (0 位負責人)C# (5,445 個分叉)batch import
area-Serializationhelp wanted

倉庫指標

星標
 (17,886 顆星)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

Version Used:

Visual studio 2019 16.8.2

Steps to Reproduce:

Compile code like this:

[DataContract]
sealed class TimeSeriesPoint
{
	[DataMember]
	public float compliance, volume;
}

Expected Behavior:

Maybe no warnings at all.

Maybe a different message, like "...will always have its default value 0, unless set by deserializing".

Actual Behavior:

Warning CS0649: Field 'TimeSeriesPoint.volume' is never assigned to, and will always have its default value 0.

This is incorrect because despite these fields are never assigned to, they won't always have a default value, due to serialization.

貢獻者指南