Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Louis <savagesoftware@gmail.com>2018-02-27 19:53:45 +0300
committerDominique Louis <savagesoftware@gmail.com>2018-03-19 21:44:31 +0300
commitf2eac7fa9898b02dc02d529d54776c884e84cd5a (patch)
tree4992ebefdec13884726e09c22da07175b91d266b /Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs
parenta088a9739ae061a53b12ab25aeba6c23ba407ed5 (diff)
Fixes to Support Nullables On Mac
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs27
1 files changed, 21 insertions, 6 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs
index 5f326b5..42f1257 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs
@@ -9,16 +9,20 @@ namespace Xamarin.PropertyEditing.Mac
{
internal class NumericEditorControl<T>
: PropertyEditorControl
- where T : struct
{
public NumericEditorControl ()
{
base.TranslatesAutoresizingMaskIntoConstraints = false;
- NumericEditor = new NumericSpinEditor ();
+ NumericEditor = new NumericSpinEditor<T> ();
NumericEditor.ValueChanged += OnValueChanged;
- TypeCode code = Type.GetTypeCode (typeof (T));
+ var t = typeof (T);
+ if (t.Name == PropertyViewModel<T>.NullableName) {
+ underlyingType = Nullable.GetUnderlyingType (t);
+ t = underlyingType;
+ }
+ TypeCode code = Type.GetTypeCode (t);
switch (code) {
case TypeCode.Double:
case TypeCode.Single:
@@ -41,7 +45,7 @@ namespace Xamarin.PropertyEditing.Mac
});
}
- protected NumericSpinEditor NumericEditor { get; set; }
+ protected NumericSpinEditor<T> NumericEditor { get; set; }
protected NSNumberFormatter Formatter {
get {
@@ -63,6 +67,14 @@ namespace Xamarin.PropertyEditing.Mac
}
}
+ internal new NumericPropertyViewModel<T> ViewModel
+ {
+ get { return (NumericPropertyViewModel<T>)base.ViewModel; }
+ set { base.ViewModel = value; }
+ }
+
+ private Type underlyingType;
+
protected override void UpdateErrorsDisplayed (IEnumerable errors)
{
if (ViewModel.HasErrors) {
@@ -85,12 +97,15 @@ namespace Xamarin.PropertyEditing.Mac
protected virtual void OnValueChanged (object sender, EventArgs e)
{
- ((PropertyViewModel<T>)ViewModel).Value = (T)Convert.ChangeType (NumericEditor.Value, typeof(T));
+ var t = typeof (T);
+ if (underlyingType != null)
+ t = underlyingType;
+ ViewModel.Value = (T)Convert.ChangeType (NumericEditor.Value, t);
}
protected override void UpdateValue()
{
- NumericEditor.Value = (double)Convert.ChangeType (((PropertyViewModel<T>)ViewModel).Value, typeof(double));
+ NumericEditor.Value = (double)Convert.ChangeType ((ViewModel).Value, typeof(double));
}
protected override void UpdateAccessibilityValues ()