Есть некоторая структура для передачи данных
[StructLayout(LayoutKind.Explicit)]
public struct SomeStruct
{
[FieldOffset(0)]
public byte v1;
[FieldOffset(1)]
public byte v2;
[FieldOffset(2)]
public float v3;
......
}
Допустим некоторые поля типа byte имеют битовые флаги нескольких переменных.(т.е. например v1 содержит 8 переменных).
На помощь создается класс SomeStructHelper
class SomeStructHelper
{
public static SomeStruct StructData
{
get
{
SomeStruct returnStruct;
BitArray bit = new BitArray(new bool[] { Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Bit8 });
Array array = Array.CreateInstance(typeof(byte), 1);
bit.CopyTo(array, 0);
returnStruct.v1 = (byte)array.GetValue(0);
..............
}
set
{
BitArray bits = new BitArray(new byte[] { value.v1});
Bit1 = bits.Get(0);
Bit2 = bits.Get(1);
...........
}
}
public static bool Bit1 { get; set; }
public static bool Bit2 { get; set; }
public static bool Bit3 { get; set; }
.....................
}
Вот вопрос: StructData лучше оставить свойством или желательно сделать два статических метода(Get и Set)?