using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Xamarin.PropertyEditing.Reflection; namespace Xamarin.PropertyEditing.Tests { internal class MockBindingEditor : IObjectEditor { public MockBindingEditor (MockBinding binding) { Target = binding; this.editor = new ReflectionObjectEditor (binding); this.editor.PropertyChanged += (sender, args) => { PropertyChanged?.Invoke (this, args); }; KnownProperties = new Dictionary { { this.editor.Properties.Single (pi => pi.Name == nameof(MockBinding.Source)), PropertyBinding.SourceProperty }, { this.editor.Properties.Single (pi => pi.Name == nameof(MockBinding.SourceParameter)), PropertyBinding.SourceParameterProperty }, { this.editor.Properties.Single (pi => pi.Name == nameof(MockBinding.Path)), PropertyBinding.PathProperty }, { this.editor.Properties.Single (pi => pi.Name == nameof(MockBinding.Converter)), PropertyBinding.ConverterProperty }, { this.editor.Properties.Single (pi => pi.Name == nameof(MockBinding.TypeLevel)), PropertyBinding.TypeLevelProperty } }; } public event EventHandler PropertyChanged; public object Target { get; } public ITypeInfo TargetType => this.editor.TargetType; public IReadOnlyCollection Properties => this.editor.Properties; public IReadOnlyDictionary KnownProperties { get; } public IObjectEditor Parent => null; public IReadOnlyList DirectChildren => null; public Task GetAssignableTypesAsync (IPropertyInfo property, bool childTypes) { return this.editor.GetAssignableTypesAsync (property, childTypes); } public Task> GetPropertyVariantsAsync (IPropertyInfo property) { throw new NotSupportedException(); } public Task RemovePropertyVariantAsync (IPropertyInfo property, PropertyVariation variant) { throw new NotSupportedException(); } public Task SetValueAsync (IPropertyInfo property, ValueInfo value, PropertyVariation variations = null) { return this.editor.SetValueAsync (property, value, variations); } public Task> GetValueAsync (IPropertyInfo property, PropertyVariation variations = null) { return this.editor.GetValueAsync (property, variations); } private readonly ReflectionObjectEditor editor; } }