最近、コンパイラの警告と (非常に役立つ) ヒントが表示され、以下のコードを書くようになりました。
私はあなたがこれを行うことができるとは思いもしませんでしたが、それは完全に合法であり、管理されていない構造体のパブリック フィールドと同様のパブリック プロパティを持つ管理された構造体を宣言できるという点でも便利です。すべてのフィールドをパラメーターとして。
私を混乱させているのは、これが明示的なパラメーターなしのコンストラクターを呼び出しているように見えることです。これはもちろん、この構造体では違法です。
この構文は常にサポートされていますか?
internal struct IconEntry
{
public byte Width { get; set; }
public byte Height { get; set; }
public byte ColorCount { get; set; }
public byte Reserved { get; set; }
public short Planes { get; set; }
public short BitCount { get; set; }
public int BytesInRes { get; set; }
public int ImageOffset { get; set; }
public IconEntry(BinaryReader reader)
: this()
{
Width = reader.ReadByte();
Height = reader.ReadByte();
ColorCount = reader.ReadByte();
Reserved = reader.ReadByte();
Planes = reader.ReadInt16();
BitCount = reader.ReadInt16();
BytesInRes = reader.ReadInt32();
ImageOffset = reader.ReadInt32();
}
}