1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- namespace InABox.Core
- {
- public class DFLayoutDateTimeFieldProperties : DFLayoutFieldProperties<DateTime, DateTime?>
- {
-
- [EditorSequence(-995)]
- [DateTimeEditor]
- public override DateTime Default { get; set; }
-
- public DFLayoutDateTimeFieldProperties()
- {
- Format = "mm HH dd MMM yy";
- }
- public string Format { get; set; }
- public override string FormatValue(DateTime? value)
- {
- return string.Format("{0" + (string.IsNullOrWhiteSpace(Format) ? "" : ":" + Format.Replace(":", "\\:")) + "}", value);
- }
- public override DateTime GetValue(DateTime? value)
- {
- return value ?? Default;
- }
- public override void SerializeValue(DFSaveStorageEntry entry, DateTime? value)
- {
- if (value != null)
- {
- entry.SetValue(value);
- }
- }
- public override DateTime? DeserializeValue(DFLoadStorageEntry entry)
- {
- var value = entry.GetValue();
- if (value is DateTime date)
- return date;
- if (DateTime.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);
- }
- }
- }
|