Represents the low-level synchronization behavior for a single list item. SyncManagerHelper needs this.
More...
Represents the low-level synchronization behavior for a single list item. SyncManagerHelper needs this.
This interface is used instead of SyncFieldFunc_Ref so that the implementation can be a struct, in order to take advantage of the CLR's ability to specialize generic methods for structs, which provides better performance by avoiding indirect calls and enabling inlining.
Example usage:
public struct SyncFields<SM> :
ISyncField<SM, Color>,
ISyncField<SM, BitArray>,
ISyncObject<SM, TwoColorBitmap>
where SM : ISyncManager
{
public Color Sync(ref SM sm, FieldId name, Color color)
{
return Color.FromArgb(sm.Sync(name, color.ToArgb()));
}
public BitArray? Sync(ref SM sm, FieldId name, BitArray? value)
{
if (sm.IsReading) {
return new BitArray(sm.SyncArray(name, Array.Empty<byte>()));
} else if (value is null) {
sm.SyncArray(name, (byte[]?) null);
} else {
byte[] bytes = new byte[(value.Length + 7) >> 3];
value.CopyTo(bytes, 0);
sm.SyncArray(name, bytes);
}
return value;
}
public TwoColorBitmap? Sync(SM sm, TwoColorBitmap? obj)
{
obj ??= new TwoColorBitmap();
obj.Color0 = sm.Sync("Color0", obj.Color0, this);
obj.Color1 = sm.Sync("Color1", obj.Color1, this);
obj.Bits = sm.Sync("Bits", obj.Bits, this)!;
return obj;
}
}
]]>