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:
authorEric Maupin <ermaup@microsoft.com>2018-04-17 23:06:04 +0300
committerEric Maupin <ermaup@microsoft.com>2018-05-01 00:53:55 +0300
commitd6321d4d839b8515d76e8ea5b5e7a5e2a3c84557 (patch)
treeded4066f25cc0391f8693c3aa6ccccb9b1834d4c /Xamarin.PropertyEditing
parent593bc542bd07146326600bb41c988def27bb8d89 (diff)
[Core] Support child assignable types
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r--Xamarin.PropertyEditing/AssignableTypesResult.cs35
-rw-r--r--Xamarin.PropertyEditing/IObjectEditor.cs5
-rw-r--r--Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs6
-rw-r--r--Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs6
-rw-r--r--Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj1
5 files changed, 46 insertions, 7 deletions
diff --git a/Xamarin.PropertyEditing/AssignableTypesResult.cs b/Xamarin.PropertyEditing/AssignableTypesResult.cs
new file mode 100644
index 0000000..b16170a
--- /dev/null
+++ b/Xamarin.PropertyEditing/AssignableTypesResult.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+
+namespace Xamarin.PropertyEditing
+{
+ public class AssignableTypesResult
+ {
+ public AssignableTypesResult (IReadOnlyList<ITypeInfo> assignableTypes)
+ {
+ if (assignableTypes == null)
+ throw new ArgumentNullException (nameof(assignableTypes));
+
+ AssignableTypes = assignableTypes;
+ }
+
+ public AssignableTypesResult (IReadOnlyList<ITypeInfo> suggestedTypes, IReadOnlyList<ITypeInfo> assignableTypes)
+ : this (assignableTypes)
+ {
+ if (suggestedTypes == null)
+ throw new ArgumentNullException (nameof(suggestedTypes));
+
+ SuggestedTypes = suggestedTypes;
+ }
+
+ public IReadOnlyList<ITypeInfo> SuggestedTypes
+ {
+ get;
+ }
+
+ public IReadOnlyList<ITypeInfo> AssignableTypes
+ {
+ get;
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.PropertyEditing/IObjectEditor.cs b/Xamarin.PropertyEditing/IObjectEditor.cs
index 9fbea05..2b53bb3 100644
--- a/Xamarin.PropertyEditing/IObjectEditor.cs
+++ b/Xamarin.PropertyEditing/IObjectEditor.cs
@@ -58,7 +58,10 @@ namespace Xamarin.PropertyEditing
/// </summary>
event EventHandler<EditorPropertyChangedEventArgs> PropertyChanged;
- Task<IReadOnlyList<ITypeInfo>> GetAssignableTypesAsync (IPropertyInfo property);
+ /// <param name="property">The property to get retrieve assignable types for.</param>
+ /// <param name="childTypes">Whether or not to return assignable types for a property's children rather than the property itself.</param>
+ /// <returns>An <see cref="AssignableTypesResult"/> instance containing the assignable types. No assignable types should use an empty array and not return <c>null</c>.</returns>
+ Task<AssignableTypesResult> GetAssignableTypesAsync (IPropertyInfo property, bool childTypes);
/*
* Dealing with async values in the context of what's possible across all target platforms is a bit complex.
diff --git a/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs b/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
index 872d706..19b8d7d 100644
--- a/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
+++ b/Xamarin.PropertyEditing/Reflection/ReflectionObjectEditor.cs
@@ -92,19 +92,19 @@ namespace Xamarin.PropertyEditing.Reflection
return Task.FromResult (info.GetHandlers (this.target));
}
- public Task<IReadOnlyList<ITypeInfo>> GetAssignableTypesAsync (IPropertyInfo property)
+ public Task<AssignableTypesResult> GetAssignableTypesAsync (IPropertyInfo property, bool childTypes)
{
return Task.Run (() => {
ReflectionPropertyInfo realInfo = (ReflectionPropertyInfo) property;
var assemblies = AppDomain.CurrentDomain.GetAssemblies ();
var entry = Assembly.GetEntryAssembly();
- return (IReadOnlyList<ITypeInfo>)assemblies.Select (a => new { Assembly = a, Info = new AssemblyInfo (a.FullName, a == entry)})
+ return new AssignableTypesResult (assemblies.Select (a => new { Assembly = a, Info = new AssemblyInfo (a.FullName, a == entry)})
.SelectMany (a =>
a.Assembly.DefinedTypes.Select (t => new { Type = t, Assembly = a }))
.AsParallel ()
.Where (t => realInfo.Type.IsAssignableFrom (t.Type))
- .Select (t => new TypeInfo (t.Assembly.Info, t.Type.Namespace, t.Type.Name)).ToList();
+ .Select (t => new TypeInfo (t.Assembly.Info, t.Type.Namespace, t.Type.Name)).ToList());
});
}
diff --git a/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs
index 15b454d..16f1b21 100644
--- a/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs
@@ -237,11 +237,11 @@ namespace Xamarin.PropertyEditing.ViewModels
private async Task<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> GetAssignableTypesAsync ()
{
- Task<IReadOnlyList<ITypeInfo>>[] typeTasks = Editors.Select (o => o.GetAssignableTypesAsync (Property)).ToArray();
- IReadOnlyList<ITypeInfo>[] lists = await Task.WhenAll (typeTasks).ConfigureAwait (false);
+ Task<AssignableTypesResult>[] typeTasks = Editors.Select (o => o.GetAssignableTypesAsync (Property, childTypes: false)).ToArray();
+ AssignableTypesResult[] lists = await Task.WhenAll (typeTasks).ConfigureAwait (false);
var assemblies = new Dictionary<IAssemblyInfo, ILookup<string, ITypeInfo>> ();
- foreach (ITypeInfo type in lists.SelectMany (t => t)) {
+ foreach (ITypeInfo type in lists.SelectMany (t => t.AssignableTypes)) {
if (!assemblies.TryGetValue (type.Assembly, out ILookup<string, ITypeInfo> types)) {
assemblies[type.Assembly] = types = new ObservableLookup<string, ITypeInfo> ();
}
diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
index fdc38df..be28bc8 100644
--- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
+++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
@@ -46,6 +46,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="AssignableTypesResult.cs" />
<Compile Include="AsyncValue.cs" />
<Compile Include="AsyncWorkQueue.cs" />
<Compile Include="BidirectionalDictionary.cs" />