public static void PersistDictionaryValue <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, PersistDictionaryItemCallback <TKey, TValue> callback) { persister.BeginObject(); var count = (ushort)value.Count; persister.PersistUInt16(ref count); persister.PersistDictionaryImpl(value, count, callback); persister.EndObject(); }
public static void PersistListWithUInt32Count <T>(this StatePersister persister, List <T> value, PersistListItemCallback <T> callback, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); var count = (uint)value.Count; persister.PersistUInt32(ref count); PersistListImpl(persister, value, count, callback); persister.EndObject(); }
public static void PersistDictionaryWithUInt32Count <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, PersistDictionaryItemCallback <TKey, TValue> callback, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); var count = (uint)value.Count; persister.PersistUInt32(ref count); persister.PersistDictionaryImpl(value, count, callback); persister.EndObject(); }
public static void PersistListWithByteCountValue <T>(this StatePersister persister, List <T> value, PersistListItemCallback <T> callback) { persister.BeginObject(); var count = (byte)value.Count; persister.PersistByte(ref count); PersistListImpl(persister, value, count, callback); persister.EndObject(); }
private static void PersistDictionaryImpl <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, uint count, PersistDictionaryItemCallback <TKey, TValue> callback) { persister.BeginArray("Items"); if (persister.Mode == StatePersistMode.Read) { value.Clear(); for (var i = 0; i < count; i++) { persister.BeginObject(); var itemKey = default(TKey); var itemValue = default(TValue); callback(persister, ref itemKey, ref itemValue); value.Add(itemKey, itemValue); persister.EndObject(); } } else { foreach (var item in value) { persister.BeginObject(); var itemKey = item.Key; var itemValue = item.Value; callback(persister, ref itemKey, ref itemValue); persister.EndObject(); } } persister.EndArray(); }
public static void PersistBitArray <TEnum>(this StatePersister persister, ref BitArray <TEnum> result, [CallerArgumentExpression("result")] string name = "") where TEnum : Enum { persister.BeginObject(name); persister.PersistVersion(1); if (persister.Mode == StatePersistMode.Read) { result.SetAll(false); } var count = (uint)result.NumBitsSet; persister.PersistUInt32(ref count); persister.BeginArray("Items"); if (persister.Mode == StatePersistMode.Read) { var stringToValueMap = Data.Ini.IniParser.GetEnumMap <TEnum>(); for (var i = 0; i < count; i++) { string stringValue = default; persister.PersistAsciiStringValue(ref stringValue); var enumValue = (TEnum)stringToValueMap[stringValue]; result.Set(enumValue, true); } } else { var valueToStringMap = Data.Ini.IniParser.GetEnumMapReverse <TEnum>(); foreach (var setBit in result.GetSetBits()) { var stringValue = valueToStringMap[setBit]; persister.PersistAsciiStringValue(ref stringValue); } } persister.EndArray(); persister.EndObject(); }
public static void PersistArrayWithUInt32Length <T>(this StatePersister persister, T[] value, PersistListItemCallback <T> callback, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); var length = (uint)value.Length; persister.PersistUInt32(ref length); if (length != value.Length) { throw new InvalidStateException(); } PersistArray(persister, value, callback, "Items"); persister.EndObject(); }
public static void PersistDateTime(this StatePersister persister, ref DateTime value, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); var year = (ushort)value.Year; persister.PersistUInt16(ref year); var month = (ushort)value.Month; persister.PersistUInt16(ref month); var day = (ushort)value.Day; persister.PersistUInt16(ref day); var dayOfWeek = (ushort)value.DayOfWeek; persister.PersistUInt16(ref dayOfWeek); var hour = (ushort)value.Hour; persister.PersistUInt16(ref hour); var minute = (ushort)value.Minute; persister.PersistUInt16(ref minute); var second = (ushort)value.Second; persister.PersistUInt16(ref second); var millisecond = (ushort)value.Millisecond; persister.PersistUInt16(ref millisecond); persister.EndObject(); if (persister.Mode == StatePersistMode.Read) { value = new DateTime(year, month, day, hour, minute, second, millisecond); } }
public static void PersistPoint2D(this StatePersister persister, ref Point2D value, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); var x = value.X; persister.PersistInt32(ref x); var y = value.Y; persister.PersistInt32(ref y); if (persister.Mode == StatePersistMode.Read) { value = new Point2D(x, y); } persister.EndObject(); }
public static void PersistRandomVariable(this StatePersister persister, ref RandomVariable value, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); var distributionType = value.DistributionType; persister.PersistEnum(ref distributionType); var low = value.Low; persister.PersistSingle(ref low); var high = value.High; persister.PersistSingle(ref high); persister.EndObject(); if (persister.Mode == StatePersistMode.Read) { value = new RandomVariable(low, high, distributionType); } }
public static void PersistColorRgbF(this StatePersister persister, ref ColorRgbF value, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); var r = value.R; persister.PersistSingle(ref r); var g = value.G; persister.PersistSingle(ref g); var b = value.B; persister.PersistSingle(ref b); persister.EndObject(); if (persister.Mode == StatePersistMode.Read) { value = new ColorRgbF(r, g, b); } }