123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using Newtonsoft.Json.Linq;
- namespace InABox.Core
- {
- public class DFLayoutDoubleFieldProperties : DFLayoutFieldProperties<double, double?>
- {
- public DFLayoutDoubleFieldProperties()
- {
- Format = "F2";
- }
- public string Format { get; set; }
- public override string FormatValue(double? value)
- {
- return string.Format("{0" + (string.IsNullOrWhiteSpace(Format) ? "" : ":" + Format) + "}", value);
- }
- public override double GetValue(double? value)
- {
- return value ?? Default;
- }
- public override void SerializeValue(DFSaveStorageEntry entry, double? value)
- {
- if(value != null)
- {
- entry.SetValue(value);
- }
- }
- public override double? DeserializeValue(DFLoadStorageEntry entry)
- {
- var value = entry.GetValue();
- if (value is double d)
- return d;
- if (double.TryParse(value as string, out var result))
- return result;
- return null;
- }
- protected override void LoadProperties()
- {
- base.LoadProperties();
- Format = GetProperty("Format", Format);
- }
- protected override void SaveProperties()
- {
- base.SaveProperties();
- SetProperty("Format", Format);
- }
- }
- }
|