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

PropertiesViewModel.cs « ViewModels « Xamarin.PropertyEditing - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e5cceb3430f1a20917795a3a24ea2b6ce2aa1a1 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Cadenza.Collections;
using Xamarin.PropertyEditing.Common;
using Xamarin.PropertyEditing.Drawing;

namespace Xamarin.PropertyEditing.ViewModels
{
	internal abstract class PropertiesViewModel
		: NotifyingObject, INotifyDataErrorInfo
	{
		public PropertiesViewModel (TargetPlatform targetPlatform)
		{
			if (targetPlatform == null)
				throw new ArgumentNullException (nameof(targetPlatform));

			TargetPlatform = targetPlatform;

			this.selectedObjects.CollectionChanged += OnSelectedObjectsChanged;
		}

		public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;

		/// <remarks>Consumers should check for <see cref="INotifyCollectionChanged"/> and hook appropriately.</remarks>
		public IReadOnlyList<EditorViewModel> Properties => this.editors;

		public IReadOnlyList<EventViewModel> Events => this.events;

		public ICollection<object> SelectedObjects => this.selectedObjects;

		public string TypeName
		{
			get { return this.typeName; }
			private set
			{
				if (this.typeName == value)
					return;

				this.typeName = value;
				OnPropertyChanged ();
			}
		}

		public bool IsObjectNameable => this.nameable != null;

		public bool IsObjectNameReadOnly
		{
			get { return this.nameReadOnly; }
			private set
			{
				if (this.nameReadOnly == value)
					return;

				this.nameReadOnly = value;
				OnPropertyChanged ();
			}
		}

		public string ObjectName
		{
			get { return this.objectName; }
			set
			{
				if (this.objectName == value)
					return;

				SetObjectName (value);
			}
		}

		public bool EventsEnabled
		{
			get { return this.eventsEnabled; }
			private set
			{
				if (this.eventsEnabled == value)
					return;

				this.eventsEnabled = value;
				OnPropertyChanged ();
			}
		}

		public TargetPlatform TargetPlatform
		{
			get;
		}

		public bool HasErrors => this.errors.IsValueCreated && this.errors.Value.Count > 0;

		public IEnumerable GetErrors (string propertyName)
		{
			if (!this.errors.IsValueCreated)
				return Enumerable.Empty<string> ();

			string error;
			if (this.errors.Value.TryGetValue (propertyName, out error))
				return new[] { error };

			return Enumerable.Empty<string> ();
		}

		public PropertyViewModel<T> GetKnownPropertyViewModel<T> (KnownProperty<T> property)
		{
			if (property == null)
				throw new ArgumentNullException (nameof (property));
			if (this.knownEditors == null)
				throw new InvalidOperationException ("Querying for known properties before they've been setup");
			if (!this.knownEditors.TryGetValue (property, out EditorViewModel model))
				throw new KeyNotFoundException ();

			var vm = model as PropertyViewModel<T>;
			if (vm == null)
				throw new InvalidOperationException ("KnownProperty doesn't return expected property view model type");

			return vm;
		}

		protected IReadOnlyList<IObjectEditor> ObjectEditors => this.objEditors;

		/// <param name="newError">The error message or <c>null</c> to clear the error.</param>
		protected void SetError (string property, string newError)
		{
			if (this.errors.IsValueCreated) {
				string prevError;
				if (this.errors.Value.TryGetValue (property, out prevError)) {
					if (prevError == newError)
						return;
				}
			}

			if (newError == null)
				this.errors.Value.Remove (property);
			else
				this.errors.Value[property] = newError;

			OnErrorsChanged (new DataErrorsChangedEventArgs (property));
		}

		// TODO: Consider having the property hooks at the top level and a map of IPropertyInfo -> PropertyViewModel
		// the hash lookup would be likely faster than doing a property info compare in every property and would
		// reduce the number event attach/detatches

		protected virtual async void OnSelectedObjectsChanged (object sender, NotifyCollectionChangedEventArgs e)
		{
			var tcs = new TaskCompletionSource<bool> ();
			var existingTask = Interlocked.Exchange (ref this.busyTask, tcs.Task);
			if (existingTask != null)
				await existingTask;

			IObjectEditor[] newEditors = null;
			IObjectEditor[] removedEditors = null;

			switch (e.Action) {
				case NotifyCollectionChangedAction.Add: {
					newEditors = await AddEditorsAsync (e.NewItems);
					break;
				}

				case NotifyCollectionChangedAction.Remove:
					removedEditors = new IObjectEditor[e.OldItems.Count];
					for (int i = 0; i < e.OldItems.Count; i++) {
						IObjectEditor editor = this.objEditors.First (oe => oe?.Target == e.OldItems[i]);
						editor.PropertyChanged -= OnObjectEditorPropertyChanged;
						INotifyCollectionChanged notifier = editor.Properties as INotifyCollectionChanged;
						if (notifier != null)
							notifier.CollectionChanged -= OnObjectEditorPropertiesChanged;

						removedEditors[i] = editor;
						this.objEditors.Remove (editor);
					}
					break;

				case NotifyCollectionChangedAction.Replace:
				case NotifyCollectionChangedAction.Move:
				case NotifyCollectionChangedAction.Reset: {
					removedEditors = new IObjectEditor[this.objEditors.Count];
					for (int i = 0; i < removedEditors.Length; i++) {
						IObjectEditor editor = this.objEditors[i];
						if (editor == null)
							continue;

						removedEditors[i] = editor;
						editor.PropertyChanged -= OnObjectEditorPropertyChanged;
						INotifyCollectionChanged notifier = editor.Properties as INotifyCollectionChanged;
						if (notifier != null)
							notifier.CollectionChanged -= OnObjectEditorPropertiesChanged;
					}

					this.objEditors.Clear ();

					newEditors = await AddEditorsAsync (this.selectedObjects);
					break;
				}
			}

			await UpdateMembersAsync (removedEditors, newEditors);
			tcs.SetResult (true);
		}

		protected virtual void OnAddEditors (IEnumerable<EditorViewModel> editors)
		{
		}

		protected virtual void OnRemoveEditors (IEnumerable<EditorViewModel> editors)
		{
		}

		protected virtual void OnClearProperties()
		{
		}

		/// <summary>
		/// Gets whether the <paramref name="viewModel"/> is the last-arranged variant property of its base property
		/// </summary>
		internal virtual bool GetIsLastVariant (PropertyViewModel viewModel)
		{
			throw new NotSupportedException();
		}

		private INameableObject nameable;
		private bool nameReadOnly;
		private bool eventsEnabled;
		private string typeName, objectName;
		private BidirectionalDictionary<KnownProperty, EditorViewModel> knownEditors;
		private readonly List<IObjectEditor> objEditors = new List<IObjectEditor> ();
		private readonly ObservableCollectionEx<EditorViewModel> editors = new ObservableCollectionEx<EditorViewModel> ();
		private readonly ObservableCollectionEx<object> selectedObjects = new ObservableCollectionEx<object> ();
		private readonly ObservableCollectionEx<EventViewModel> events = new ObservableCollectionEx<EventViewModel> (); 
		private readonly Lazy<Dictionary<string, string>> errors = new Lazy<Dictionary<string, string>>();

		private void OnErrorsChanged (DataErrorsChangedEventArgs e)
		{
			ErrorsChanged?.Invoke (this, e);
		}

		private void OnObjectEditorPropertyChanged (object sender, EditorPropertyChangedEventArgs e)
		{
			if (!e.Property.HasVariations ())
				return;

			OnVariantsChanged (e.Property, EventArgs.Empty);
		}

		private async void OnVariantsChanged (object sender, EventArgs e)
		{
			IPropertyInfo property = sender as IPropertyInfo;
			if (property == null)
				property = ((PropertyViewModel)sender).Property;

			using (await AsyncWork.RequestAsyncWork (this)) {
				var variationsTask = GetVariationsAsync (property);

				PropertyViewModel baseVm = null;
				var properties = new Dictionary<PropertyVariation, PropertyViewModel> ();
				foreach (PropertyViewModel pvm in this.editors.OfType<PropertyViewModel> ()) {
					if (!Equals (property, pvm.Property))
						continue;

					if (pvm.Variation == null)
						baseVm = pvm;
					else
						properties.Add (pvm.Variation, pvm);
				}

				if (baseVm == null)
					throw new InvalidOperationException ("Base property view model couldn't be found");

				var variations = await variationsTask;
				baseVm.HasVariantChildren = variations.Count > 0;

				List<PropertyViewModel> toAdd = new List<PropertyViewModel> ();
				foreach (PropertyVariation variation in variations) {
					if (!properties.Remove (variation)) {
						toAdd.Add (CreateViewModel (property, variation));
					}
				}

				if (properties.Count > 0) {
					var toRemove = new List<PropertyViewModel> ();
					foreach (var kvp in properties) {
						toRemove.Add (kvp.Value);
					}

					RemoveProperties (toRemove);
				}

				if (toAdd.Count > 0)
					AddProperties (toAdd);
			}
		}

		private void AddProperties (IReadOnlyList<EditorViewModel> newEditors)
		{
			if (this.knownEditors != null) {
				// Only properties common across obj editors will be listed, so knowns should also be common
				var knownProperties = newEditors[0].Editors.First().KnownProperties;
				if (knownProperties != null && knownProperties.Count > 0) {
					foreach (var editorvm in newEditors) {
						var prop = editorvm as PropertyViewModel;
						if (prop == null)
							continue;

						if (knownProperties.TryGetValue (prop.Property, out KnownProperty known)) {
							this.knownEditors[known] = editorvm;
						}
					}
				}
			}

			this.editors.AddRange (newEditors);
			OnAddEditors (newEditors);
		}

		private void RemoveProperties (IReadOnlyList<EditorViewModel> oldEditors)
		{
			if (this.knownEditors != null) {
				foreach (EditorViewModel old in oldEditors) {
					this.knownEditors.Inverse.Remove (old);
				}
			}

			this.editors.RemoveRange (oldEditors);
			OnRemoveEditors (oldEditors);
		}

		private async void SetObjectName (string value)
		{
			if (this.nameable == null)
				return;

			try {
				await this.nameable.SetNameAsync (value);
			} catch (Exception ex) {
				AggregateException aggregate = ex as AggregateException;
				if (aggregate != null) {
					aggregate = aggregate.Flatten ();
					ex = aggregate.InnerExceptions[0];
				}

				SetError (nameof(ObjectName), ex.ToString());
			} finally {
				SetCurrentObjectName (value, isReadonly: false);
			}
		}

		private void SetNameable (INameableObject nameable)
		{
			this.nameable = nameable;
			OnPropertyChanged (nameof (IsObjectNameable));
		}

		private void SetCurrentObjectName (string value, bool isReadonly)
		{
			IsObjectNameReadOnly = isReadonly;
			this.objectName = value;
			OnPropertyChanged (nameof (ObjectName));
		}

		private void ClearMembers()
		{
			TypeName = null;
			SetNameable (null);
			SetCurrentObjectName (null, isReadonly: true);
			this.editors.Clear ();
			this.events.Clear ();
			OnClearProperties ();
		}

		private async Task UpdateMembersAsync (IObjectEditor[] removedEditors = null, IObjectEditor[] newEditors = null)
		{
			if (this.objEditors.Count == 0) {
				ClearMembers ();
				return;
			}

			IObjectEditor editor = this.objEditors[0];

			Task<string> nameQuery = null;
			INameableObject firstNameable = editor as INameableObject;
			if (this.objEditors.Count == 1) {
				nameQuery = firstNameable?.GetNameAsync ();
			}

			IObjectEventEditor events = editor as IObjectEventEditor;
			var newEventSet = new HashSet<IEventInfo> (events?.Events ?? Enumerable.Empty<IEventInfo> ());

			bool knownProperties = (editor?.KnownProperties?.Count ?? 0) > 0;
			string newTypeName = editor?.TargetType.Name;
			var newPropertySet = new HashSet<IPropertyInfo> (editor?.Properties ?? Enumerable.Empty<IPropertyInfo>());
			for (int i = 1; i < this.objEditors.Count; i++) {
				editor = this.objEditors[i];
				if (editor == null)
					continue;

				newPropertySet.IntersectWith (editor.Properties);

				if (editor is IObjectEventEditor) {
					events = (IObjectEventEditor)editor;
					newEventSet.IntersectWith (events.Events);
				}

				if (firstNameable == null)
					firstNameable = editor as INameableObject;

				if (newTypeName != editor.TargetType.Name)
					newTypeName = String.Format (PropertyEditing.Properties.Resources.MultipleTypesSelected, this.objEditors.Count);

				if (!knownProperties)
					knownProperties = (editor.KnownProperties?.Count ?? 0) > 0;
			}

			TypeName = newTypeName;

			if (knownProperties && this.knownEditors == null)
				this.knownEditors = new BidirectionalDictionary<KnownProperty, EditorViewModel> ();

			await UpdatePropertiesAsync (newPropertySet, removedEditors, newEditors);

			EventsEnabled = events != null;
			UpdateEvents (newEventSet, removedEditors, newEditors);

			string name = (this.objEditors.Count > 1) ? String.Format (PropertyEditing.Properties.Resources.MultipleObjectsSelected, this.objEditors.Count) : PropertyEditing.Properties.Resources.NoName;
			if (this.objEditors.Count == 1) {
				string tname = nameQuery?.Result;
				if (tname != null)
					name = tname;
			}

			SetNameable (firstNameable);
			SetCurrentObjectName (name, this.objEditors.Count > 1);
		}

		private void UpdateEvents (HashSet<IEventInfo> newSet, IObjectEditor[] removedEditors = null, IObjectEditor[] newEditors = null)
		{
			if (this.objEditors.Count > 1) {
				this.events.Clear ();
				return;
			}

			var toRemove = new List<EventViewModel> ();
			foreach (EventViewModel vm in this.events.ToArray ()) {
				if (!newSet.Remove (vm.Event)) {
					toRemove.Add (vm);
					vm.Editors.Clear ();
					continue;
				}

				if (removedEditors != null) {
					for (int i = 0; i < removedEditors.Length; i++)
						vm.Editors.Remove (removedEditors[i]);
				}

				if (newEditors != null) {
					for (int i = 0; i < newEditors.Length; i++)
						vm.Editors.Add (newEditors[i]);
				}
			}

			if (toRemove.Count > 0)
				this.events.RemoveRange (toRemove);
			if (newSet.Count > 0) {
				this.events.Reset (this.events.Concat (newSet.Select (i => new EventViewModel (TargetPlatform, i, this.objEditors))).OrderBy (e => e.Event.Name).ToArray());
			}
		}

		private async Task UpdatePropertiesAsync (HashSet<IPropertyInfo> newSet, IObjectEditor[] removedEditors = null, IObjectEditor[] newEditors = null)
		{
			Dictionary<IPropertyInfo, Dictionary<PropertyVariation, PropertyViewModel>> variations = null;
			List<PropertyViewModel> toRemove = new List<PropertyViewModel> ();
			foreach (PropertyViewModel vm in this.editors.ToArray ()) {
				if (!newSet.Contains (vm.Property)) {
					toRemove.Add (vm);
					vm.Editors.Clear ();
					continue;
				}

				if (!vm.HasVariations) {
					newSet.Remove (vm.Property);
				} else if (vm.Variation != null) {
					if (variations == null)
						variations = new Dictionary<IPropertyInfo, Dictionary<PropertyVariation, PropertyViewModel>> ();
					if (!variations.TryGetValue (vm.Property, out Dictionary<PropertyVariation, PropertyViewModel> variantVms))
						variations[vm.Property] = variantVms = new Dictionary<PropertyVariation, PropertyViewModel> ();

					variantVms.Add (vm.Variation, vm);
				}

				if (removedEditors != null) {
					for (int i = 0; i < removedEditors.Length; i++)
						vm.Editors.Remove (removedEditors[i]);
				}

				if (newEditors != null) {
					for (int i = 0; i < newEditors.Length; i++)
						vm.Editors.Add (newEditors[i]);
				}
			}

			if (toRemove.Count > 0)
				RemoveProperties (toRemove);
			if (newSet.Count > 0) {
				toRemove = new List<PropertyViewModel> ();

				List<EditorViewModel> newVms = new List<EditorViewModel> ();
				foreach (IPropertyInfo property in newSet) {
					if (variations != null && variations.TryGetValue (property, out Dictionary<PropertyVariation, PropertyViewModel> propertyVariations)) {
						foreach (PropertyVariation variation in await GetVariationsAsync (property)) {
							if (propertyVariations.Remove (variation))
								continue;

							newVms.Add (CreateViewModel (property, variation));
						}

						foreach (var kvp in propertyVariations) {
							toRemove.Add (kvp.Value);
						}
					} else if (property.HasVariations()) {
						newVms.AddRange (await GetViewModelsAsync (property));
					} else {
						newVms.Add (CreateViewModel (property));
					}
				}

				if (toRemove.Count > 0) {
					RemoveProperties (toRemove);
				}

				AddProperties (newVms);
			}
		}

		private async Task<IObjectEditor[]> AddEditorsAsync (IList newItems)
		{
			Task<IObjectEditor>[] newEditorTasks = new Task<IObjectEditor>[newItems.Count];
			for (int i = 0; i < newEditorTasks.Length; i++) {
				newEditorTasks[i] = TargetPlatform.EditorProvider.GetObjectEditorAsync (newItems[i]);
			}

			IObjectEditor[] newEditors = await Task.WhenAll (newEditorTasks);
			for (int i = 0; i < newEditors.Length; i++) {
				IObjectEditor editor = newEditors[i];
				if (editor == null)
					continue;

				editor.PropertyChanged += OnObjectEditorPropertyChanged;
				var notifier = editor.Properties as INotifyCollectionChanged;
				if (notifier != null)
					notifier.CollectionChanged += OnObjectEditorPropertiesChanged;
			}

			this.objEditors.AddRange (newEditors);
			return newEditors;
		}

		private async void OnObjectEditorPropertiesChanged (object sender, NotifyCollectionChangedEventArgs e)
		{
			var tcs = new TaskCompletionSource<bool> ();
			var existingTask = Interlocked.Exchange (ref this.busyTask, tcs.Task);
			if (existingTask != null)
				await existingTask;

			await UpdateMembersAsync ();

			tcs.SetResult (true);
		}

		private async Task<IReadOnlyCollection<PropertyVariation>> GetVariationsAsync (IPropertyInfo property)
		{
			var variantTasks = new List<Task<IReadOnlyCollection<PropertyVariation>>> (ObjectEditors.Count);
			for (int i = 0; i < ObjectEditors.Count; i++) {
				variantTasks.Add (ObjectEditors[i].GetPropertyVariantsAsync (property));
			}

			return (await Task.WhenAll (variantTasks)).SelectMany (vs => vs).Distinct ().ToList ();
		}

		private async Task<IReadOnlyList<PropertyViewModel>> GetViewModelsAsync (IPropertyInfo property)
		{
			PropertyViewModel baseVm = CreateViewModel (property);
			var vms = new List<PropertyViewModel> { baseVm };

			if (baseVm.HasVariations) {
				using (await AsyncWork.RequestAsyncWork (this)) {
					var variants = await GetVariationsAsync (property);
					baseVm.HasVariantChildren = variants.Count > 0;
					if (baseVm.HasVariantChildren) {
						foreach (PropertyVariation variant in variants) {
							vms.Add (CreateViewModel (property, variant));
						}
					}
				}
			}

			return vms;
		}

		private PropertyViewModel CreateViewModel (IPropertyInfo property, PropertyVariation variant = null)
		{
			PropertyViewModel vm;
			Type[] interfaces = property.GetType ().GetInterfaces ();

			Type hasPredefinedValues = interfaces.FirstOrDefault (t => t.IsGenericType && t.GetGenericTypeDefinition () == typeof(IHavePredefinedValues<>));
			if (hasPredefinedValues != null) {
				bool combinable = (bool) hasPredefinedValues.GetProperty (nameof(IHavePredefinedValues<bool>.IsValueCombinable)).GetValue (property);
				Type type = combinable
					? typeof(CombinablePropertyViewModel<>).MakeGenericType (hasPredefinedValues.GenericTypeArguments[0])
					: typeof(PredefinedValuesViewModel<>).MakeGenericType (hasPredefinedValues.GenericTypeArguments[0]);

				vm = (PropertyViewModel) Activator.CreateInstance (type, TargetPlatform, property, this.objEditors, variant);
			} else if (ViewModelMap.TryGetValue (property.Type, out var vmFactory))
				vm = vmFactory (TargetPlatform, property, this.objEditors, variant);
			else
				vm = new StringPropertyViewModel (TargetPlatform, property, this.objEditors, variant);

			vm.Parent = this;
			vm.VariantsChanged += OnVariantsChanged;
			return vm;
		}

		private Task busyTask;

		protected internal static AsyncWorkQueue AsyncWork
		{
			get;
		} = new AsyncWorkQueue();

		private static readonly Dictionary<Type, Func<TargetPlatform, IPropertyInfo, IEnumerable<IObjectEditor>, PropertyVariation, PropertyViewModel>> ViewModelMap = new Dictionary<Type, Func<TargetPlatform, IPropertyInfo, IEnumerable<IObjectEditor>, PropertyVariation, PropertyViewModel>> {
			{ typeof(DateTime), (tp,p,e,v) => new PropertyViewModel<DateTime> (tp, p, e, v) },
			{ typeof(TimeSpan), (tp,p,e,v) => new PropertyViewModel<TimeSpan> (tp, p, e, v) },
			{ typeof(char), (tp,p,e,v) => new PropertyViewModel<char> (tp, p, e, v) },
			{ typeof(string), (tp,p,e,v) => new StringPropertyViewModel (tp, p, e, v) },
			{ typeof(bool), (tp,p,e,v) => new PropertyViewModel<bool?> (tp, p, e, v) },
			{ typeof(float), (tp,p,e,v) => new NumericPropertyViewModel<float?> (tp, p, e, v) },
			{ typeof(double), (tp,p,e,v) => new NumericPropertyViewModel<double?> (tp, p, e, v) },
			{ typeof(int), (tp,p,e,v) => new NumericPropertyViewModel<int?> (tp, p, e, v) },
			{ typeof(long), (tp,p,e,v) => new NumericPropertyViewModel<long?> (tp, p, e, v) },
			{ typeof(CommonSolidBrush), (tp,p,e,v) => new BrushPropertyViewModel (tp, p, e, v, new[] {CommonBrushType.NoBrush, CommonBrushType.Solid, CommonBrushType.MaterialDesign, CommonBrushType.Resource }) },
			{ typeof(CommonColor), (tp,p,e,v) => new BrushPropertyViewModel (tp, p, e, v, new[] {CommonBrushType.NoBrush, CommonBrushType.Solid, CommonBrushType.MaterialDesign, CommonBrushType.Resource }) },
			{ typeof(CommonBrush), (tp,p,e,v) => new BrushPropertyViewModel (tp, p, e, v) },
			{ typeof(CommonPoint), (tp,p,e,v) => new PointPropertyViewModel (tp, p, e, v) },
			{ typeof(CommonSize), (tp,p,e,v) => new SizePropertyViewModel (tp, p, e, v) },
			{ typeof(CommonRectangle), (tp,p,e,v) => new RectanglePropertyViewModel (tp, p, e, v) },
			{ typeof(CommonThickness), (tp,p,e,v) => new ThicknessPropertyViewModel (tp, p, e, v) },
			{ typeof(IList), (tp,p,e,v) => new CollectionPropertyViewModel (tp, p ,e, v) },
			{ typeof(BindingSource), (tp,p,e,v) => new PropertyViewModel<BindingSource> (tp, p, e, v) },
			{ typeof(Resource), (tp,p,e,v) => new PropertyViewModel<Resource> (tp, p, e, v) },
			{ typeof(FilePath), (tp,p,e,v) => new PropertyViewModel<FilePath> (tp, p, e, v) },
			{ typeof(object), (tp,p,e,v) => new ObjectPropertyViewModel (tp, p, e, v) },
			{ typeof(ITypeInfo), (tp,p,e,v) => new TypePropertyViewModel (tp, p, e, v) },
			{ typeof(CommonRatio), (tp, p, e, v) => new RatioViewModel (tp, p, e, v) },
		};
	}
}