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
|
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
namespace Xamarin.PropertyEditing
{
public interface IResourceProvider
{
event EventHandler<ResourcesChangedEventArgs> ResourcesChanged;
/// <summary>
/// Gets whether or not the resource provider can create resources.
/// </summary>
bool CanCreateResources { get; }
/// <summary>
/// Gets the resources available to the given <paramref name="target"/> and <paramref name="property"/>.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="property"/> or <paramref name="target"/> is <c>null</c>.</exception>
/// <remarks>
/// <para>
/// Returned resources can either be of base class <see cref="Resource"/> or, whenever possible, of <see cref="Resource{T}"/>
/// including their relative representative value. This mean things like dynamic resources should, if possible, do a lookup
/// of its value relative to the <paramref name="target" /> and provide that value.
/// </para>
/// </remarks>
Task<IReadOnlyList<Resource>> GetResourcesAsync (object target, IPropertyInfo property, CancellationToken cancelToken);
/// <summary>
/// Gets resource sources relative to the provided <paramref name="target"/>.
/// </summary>
Task<IReadOnlyList<ResourceSource>> GetResourceSourcesAsync (object target);
/// <summary>
/// Gets resource sources relative to the provided <paramref name="target"/> and <paramref name="property"/>.
/// </summary>
Task<IReadOnlyList<ResourceSource>> GetResourceSourcesAsync (object target, IPropertyInfo property);
/// <summary>
/// Gets an unused type-appropriate resource key for a value of the <paramref name="property"/> being turned into a resource.
/// </summary>
Task<string> SuggestResourceNameAsync (IReadOnlyCollection<object> targets, IPropertyInfo property);
/// <summary>
/// Gets an unused type-appropriate resource key for a new resource of <paramref name="resourceType"/>.
/// </summary>
Task<string> SuggestResourceNameAsync (IReadOnlyCollection<object> targets, ITypeInfo resourceType);
/// <summary>
/// Checks for issues creating a resource in the given <paramref name="source"/> with <paramref name="name"/> such as name in use, or would be overriden.
/// </summary>
Task<ResourceCreateError> CheckNameErrorsAsync (object target, ResourceSource source, string name);
/// <typeparam name="T">The representation type.</typeparam>
/// <param name="value">The value of the resource in it's representative form.</param>
/// <exception cref="NotSupportedException"><see cref="CanCreateResources"/> is <c>false</c>.</exception>
/// <exception cref="DuplicateNameException"><paramref name="name"/> is already present in the given <paramref name="source"/>.</exception>
Task<Resource> CreateResourceAsync<T> (ResourceSource source, string name, T value);
}
public class ResourceCreateError
{
public ResourceCreateError (string message, bool isWarning)
{
if (message == null)
throw new ArgumentNullException (nameof(message));
IsWarning = isWarning;
Message = message;
}
/// <summary>
/// Gets or sets the localized description of the error
/// </summary>
public string Message
{
get;
}
/// <summary>
/// Gets or sets whether the error message is just a warning, thereby not preventing creation
/// </summary>
public bool IsWarning
{
get;
}
}
public class ResourcesChangedEventArgs
: EventArgs
{
public ResourcesChangedEventArgs ()
{
}
public ResourcesChangedEventArgs (ResourceSource source)
{
if (source == null)
throw new ArgumentNullException (nameof(source));
Source = source;
}
public ResourceSource Source
{
get;
}
}
}
|