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

PropertyEditorSelector.cs « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fc73b3616ec2b72e75560dca1ecc35d058061e7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Drawing;
using Xamarin.PropertyEditing.Common;
using Xamarin.PropertyEditing.Drawing;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Mac
{
	internal class PropertyEditorSelector
	{
		public virtual IEditorView GetEditor (IHostResourceProvider hostResources, EditorViewModel vm)
		{
			if (hostResources == null)
				throw new ArgumentNullException (nameof (hostResources));

			Type[] genericArgs = null;
			Type controlType;
			Type propertyType = vm.GetType ();
			if (!ViewModelTypes.TryGetValue (propertyType, out controlType)) {
				if (propertyType.IsConstructedGenericType) {
					genericArgs = propertyType.GetGenericArguments ();
					propertyType = propertyType.GetGenericTypeDefinition ();
					ViewModelTypes.TryGetValue (propertyType, out controlType);
				}
			}

			if (controlType == null)
				return null;

			if (controlType.IsGenericTypeDefinition) {
				if (genericArgs == null)
					genericArgs = propertyType.GetGenericArguments ();

				controlType = controlType.MakeGenericType (genericArgs);
			}

			return (IEditorView)Activator.CreateInstance (controlType, hostResources);
		}

		private static readonly Dictionary<Type, Type> ViewModelTypes = new Dictionary<Type, Type> {
			{typeof (PropertyViewModel<DateTime>), typeof (DateTimeEditorControl)},
			{typeof (PropertyViewModel<TimeSpan>), typeof(TimeSpanEditorControl)},
			{typeof (PropertyViewModel<char>), typeof(CharEditorControl)},
			{typeof (StringPropertyViewModel), typeof (StringEditorControl)},
			{typeof (NumericPropertyViewModel<>), typeof (NumericEditorControl<>)},
			{typeof (PropertyViewModel<bool?>), typeof (BooleanEditorControl)},
			{typeof (PropertyViewModel<FilePath>), typeof (FilePathEditorControl)},
			{typeof (PredefinedValuesViewModel<>), typeof(PredefinedValuesEditor<>)},
			{typeof (CombinablePropertyViewModel<>), typeof(CombinablePropertyEditor<>)},
			{typeof (PointPropertyViewModel), typeof (CommonPointEditorControl) },
			{typeof (RectanglePropertyViewModel), typeof (CommonRectangleEditorControl) },
			{typeof (SizePropertyViewModel), typeof (CommonSizeEditorControl) },
			{typeof (PropertyViewModel<Point>), typeof (SystemPointEditorControl)},
			{typeof (PropertyViewModel<Size>), typeof (SystemSizeEditorControl)},
			{typeof (PropertyViewModel<Rectangle>), typeof (SystemRectangleEditorControl)},
			{typeof (BrushPropertyViewModel), typeof (BrushEditorControl)},
			{typeof (RatioViewModel), typeof (RatioEditorControl<CommonRatio>)},
			{typeof (ThicknessPropertyViewModel), typeof (CommonThicknessEditorControl) },
			{typeof (PropertyGroupViewModel), typeof (GroupEditorControl)},
			{typeof (ObjectPropertyViewModel), typeof (ObjectEditorControl)},
			{typeof (TypePropertyViewModel), typeof (TypeEditorControl)},
			{typeof (CollectionPropertyViewModel), typeof (CollectionInlineEditorControl)},
			{typeof (PropertyViewModel<Date>), typeof (DateEditorControl)},
			{typeof (PropertyViewModel<Time>), typeof (TimeEditorControl)},
		};
	}
}