diff options
author | Dominique Louis <dolouis@microsoft.com> | 2020-10-08 18:09:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 18:09:21 +0300 |
commit | d820cccf8bb64a27b02cea4d9ad72a742dc4eb8f (patch) | |
tree | d43772fd3d8f19312cb7cbe20409e53c7be5cff2 /Xamarin.PropertyEditing | |
parent | 322d6c8f8298d519c94bad0f745b53bc2ebfed1f (diff) |
Refactor to have individual Date and Time Controls for better mapping… (#756)
* Refactor to have individual Date and Time Controls for better mapping for .Forms
* Add default control mapping to the TypeMap
* Call our initialise value method.
* Use custom controls and converters for our custom Date/Time
* Let's return the 'broken' string, if an error occurs, until they correct it.
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r-- | Xamarin.PropertyEditing/Common/Date.cs | 60 | ||||
-rw-r--r-- | Xamarin.PropertyEditing/Common/Time.cs | 59 | ||||
-rw-r--r-- | Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs | 2 |
3 files changed, 121 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing/Common/Date.cs b/Xamarin.PropertyEditing/Common/Date.cs new file mode 100644 index 0000000..7332349 --- /dev/null +++ b/Xamarin.PropertyEditing/Common/Date.cs @@ -0,0 +1,60 @@ +using System; + +namespace Xamarin.PropertyEditing.Common +{ + public class Date : IEquatable<Date> + { + private readonly DateTime dateTime; + + public Date (DateTime dateTime) + { + this.dateTime = dateTime; + } + + public DateTime DateTime { + get{ + return this.dateTime; + } + } + + public override bool Equals (object obj) + { + if (obj == null) + return false; + if ((obj is Date d)) + return Equals (d); + else + return false; + } + + public bool Equals (Date other) + { + if (other == null) + return false; + return this.dateTime.Equals (other); + } + + public override int GetHashCode () + { + var hashCode = 1861433795; + unchecked { + hashCode = hashCode * -1521134295 + this.dateTime.GetHashCode (); + } + return hashCode; + }
+
+ public override string ToString ()
+ {
+ return this.dateTime.ToShortDateString ();
+ }
+
+ public static Date Parse (string value)
+ {
+ try {
+ return new Date (DateTime.Parse (value));
+ } catch (Exception) {
+ return null;
+ }
+ }
+ } +}
\ No newline at end of file diff --git a/Xamarin.PropertyEditing/Common/Time.cs b/Xamarin.PropertyEditing/Common/Time.cs new file mode 100644 index 0000000..9905c40 --- /dev/null +++ b/Xamarin.PropertyEditing/Common/Time.cs @@ -0,0 +1,59 @@ +using System; + +namespace Xamarin.PropertyEditing.Common +{ + public class Time : IEquatable<Time> + { + private readonly DateTime dateTime; + + public DateTime DateTime { + get { + return this.dateTime; + } + } + + public Time (DateTime dateTime) + { + this.dateTime = dateTime; + } + + public override bool Equals (object obj) + { + if (obj == null) + return false; + if ((obj is Time d)) + return Equals (d); + else + return false; + } + + public bool Equals (Time other) + { + if (other == null) + return false; + return this.dateTime.Equals (other.DateTime); + } + + public override int GetHashCode () + { + var hashCode = 1861433795; + unchecked { + hashCode = hashCode * -1521134295 + this.dateTime.GetHashCode (); + } + return hashCode; + } + public override string ToString () + { + return this.dateTime.ToLongTimeString (); + } + + public static Time Parse(string value)
+ {
+ try {
+ return new Time (DateTime.Parse (value));
+ } catch (Exception) {
+ return null;
+ }
+ } + } +}
\ No newline at end of file diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs index 5862ad9..8df2740 100644 --- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs @@ -656,6 +656,8 @@ namespace Xamarin.PropertyEditing.ViewModels { typeof(ITypeInfo), (tp,p,e,v) => new TypePropertyViewModel (tp, p, e, v) }, { typeof(CommonRatio), (tp, p, e, v) => new RatioViewModel (tp, p, e, v) }, { typeof(AutoResizingFlags), (tp, p, e, v) => new AutoResizingPropertyViewModel (tp, p, e, v) }, + { typeof(Date), (tp, p, e, v) => new PropertyViewModel<Date> (tp, p, e, v) }, + { typeof(Time), (tp, p, e, v) => new PropertyViewModel<Time> (tp, p, e, v) }, }; } } |