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

MockControl.cs « MockControls « Xamarin.PropertyEditing.Tests - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7685ba56e3f4747dec08442d992beb246b2a9f3 (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
using System;
using System.Collections.Generic;
using Cadenza.Collections;
using Xamarin.PropertyEditing.Tests.MockPropertyInfo;

namespace Xamarin.PropertyEditing.Tests.MockControls
{
	public class MockControl
	{
		public IReadOnlyDictionary<string, IPropertyInfo> Properties => this.properties;

		public IReadOnlyDictionary<string, IEventInfo> Events => this.events;

		public void AddProperty<T> (string name, string category = null,
			bool canWrite = true, bool flag = false,
			IEnumerable<Type> converterTypes = null,
			string description = null, ValueSources valueSources = ValueSources.Local | ValueSources.Default | ValueSources.Binding)
		{
			IPropertyInfo propertyInfo;
			if (typeof(T).IsEnum) {
				var underlyingType = typeof (T).GetEnumUnderlyingType ();
				var enumPropertyInfoType = typeof (MockEnumPropertyInfo<,>)
					.MakeGenericType (underlyingType, typeof (T));
				propertyInfo = (IPropertyInfo)Activator.CreateInstance (enumPropertyInfoType, name, description, category, canWrite, flag, converterTypes);
			} else {
				propertyInfo = new MockPropertyInfo<T> (name, description, category, canWrite, converterTypes, valueSources);
			}

			AddProperty<T> (propertyInfo);
		}

		public void AddProperty<T> (IPropertyInfo propertyInfo)
		{
			this.properties.Add (propertyInfo.Name, propertyInfo);
		}

		public void AddReadOnlyProperty<T> (string name, string category = null)
		{
			AddProperty<T> (name, category, false);
		}

		public void AddEvent (string name)
		{
			var eventInfo = new MockEventInfo (name);
			this.events.Add (name, eventInfo);
		}

		public void AddEvents (params string[] names)
		{
			foreach (var name in names) {
				AddEvent (name);
			}
		}

		public class NotImplemented { }

		private readonly OrderedDictionary<string, IEventInfo> events = new OrderedDictionary<string, IEventInfo> ();
		private readonly OrderedDictionary<string, IPropertyInfo> properties = new OrderedDictionary<string, IPropertyInfo> ();
	}
}