diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-04-17 23:59:44 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-17 14:59:44 -0700 |
commit | cdd6d4defc844b605890e7ad731e27e373b09bf4 (patch) | |
tree | ddf897b6bf475273a247891898a6c7daf7fb2079 /Xamarin.Forms.Core/ResourceDictionary.cs | |
parent | 0b10ab0c130c814b4ab1595c8d13c4c6c9c9d5df (diff) | |
download | xamarin-forms-cdd6d4defc844b605890e7ad731e27e373b09bf4.tar.gz xamarin-forms-cdd6d4defc844b605890e7ad731e27e373b09bf4.tar.bz2 xamarin-forms-cdd6d4defc844b605890e7ad731e27e373b09bf4.zip |
Merged ResourceDictionary (#97)
* [X] Support Merged RD
* [X] Support RD as xaml roots
* [XamlC] I have no idea how that used to work before
* [C] Remove debugging statements
* fix docs
Diffstat (limited to 'Xamarin.Forms.Core/ResourceDictionary.cs')
-rw-r--r-- | Xamarin.Forms.Core/ResourceDictionary.cs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/Xamarin.Forms.Core/ResourceDictionary.cs b/Xamarin.Forms.Core/ResourceDictionary.cs index b19773ff..e5e08bc6 100644 --- a/Xamarin.Forms.Core/ResourceDictionary.cs +++ b/Xamarin.Forms.Core/ResourceDictionary.cs @@ -2,13 +2,38 @@ using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Reflection; +using System.Linq; namespace Xamarin.Forms { - public sealed class ResourceDictionary : IResourceDictionary, IDictionary<string, object> + public class ResourceDictionary : IResourceDictionary, IDictionary<string, object> { readonly Dictionary<string, object> _innerDictionary = new Dictionary<string, object>(); + Type _mergedWith; + [TypeConverter (typeof(TypeTypeConverter))] + public Type MergedWith { + get { return _mergedWith; } + set { + if (_mergedWith == value) + return; + _mergedWith = value; + if (_mergedWith == null) + return; + + _mergedInstance = _mergedWith.GetTypeInfo().BaseType.GetTypeInfo().DeclaredMethods.First(mi => mi.Name == "GetInstance").Invoke(null, new object[] {_mergedWith}) as ResourceDictionary; + } + } + + static ResourceDictionary _instance; + static ResourceDictionary GetInstance(Type type) + { + return _instance ?? (_instance = ((ResourceDictionary)Activator.CreateInstance (type))); + } + + ResourceDictionary _mergedInstance; + void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item) { ((ICollection<KeyValuePair<string, object>>)_innerDictionary).Add(item); @@ -94,7 +119,7 @@ namespace Xamarin.Forms public bool TryGetValue(string key, out object value) { - return _innerDictionary.TryGetValue(key, out value); + return _innerDictionary.TryGetValue(key, out value) || (_mergedInstance != null && _mergedInstance.TryGetValue(key, out value)); } event EventHandler<ResourcesChangedEventArgs> IResourceDictionary.ValuesChanged |