diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-03-16 20:09:22 +0100 |
---|---|---|
committer | Samantha Houts <samantha@teamredwall.com> | 2017-03-16 12:09:22 -0700 |
commit | 467c1befa1379c2644a3607d87db9a6178575306 (patch) | |
tree | dd5153c7d38ca310177f56a24587ad69d56f0498 /Xamarin.Forms.Xaml/XamlLoader.cs | |
parent | eb8b4d19450e3264fdd20e964f48facca6521070 (diff) | |
download | xamarin-forms-467c1befa1379c2644a3607d87db9a6178575306.tar.gz xamarin-forms-467c1befa1379c2644a3607d87db9a6178575306.tar.bz2 xamarin-forms-467c1befa1379c2644a3607d87db9a6178575306.zip |
Resource loading (#815)
* Resource Loader
* Replace XamlLoader API by ResourceLoader for the Previewer
* instruct generated IL to use the resourceLoader
* [docs] update docs
* oops
* [docs] fix docs
Diffstat (limited to 'Xamarin.Forms.Xaml/XamlLoader.cs')
-rw-r--r-- | Xamarin.Forms.Xaml/XamlLoader.cs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Xamarin.Forms.Xaml/XamlLoader.cs b/Xamarin.Forms.Xaml/XamlLoader.cs index 7fee40da..cdf73bdd 100644 --- a/Xamarin.Forms.Xaml/XamlLoader.cs +++ b/Xamarin.Forms.Xaml/XamlLoader.cs @@ -32,9 +32,11 @@ using System.IO; using System.Reflection; using System.Text.RegularExpressions; using System.Xml; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Xaml.Internals { + [Obsolete ("Replaced by ResourceLoader")] public static class XamlLoader { public static Func<Type, string> XamlFileProvider { get; internal set; } @@ -44,7 +46,7 @@ namespace Xamarin.Forms.Xaml.Internals namespace Xamarin.Forms.Xaml { - internal static class XamlLoader + static class XamlLoader { static readonly Dictionary<Type, string> XamlResources = new Dictionary<Type, string>(); @@ -75,7 +77,9 @@ namespace Xamarin.Forms.Xaml XamlParser.ParseXaml (rootnode, reader); Visit (rootnode, new HydratationContext { RootElement = view, - DoNotThrowOnExceptions = Xamarin.Forms.Xaml.Internals.XamlLoader.DoNotThrowOnExceptions +#pragma warning disable 0618 + ExceptionHandler = ResourceLoader.ExceptionHandler ?? (Internals.XamlLoader.DoNotThrowOnExceptions ? e => { }: (Action<Exception>)null) +#pragma warning restore 0618 }); break; } @@ -99,7 +103,7 @@ namespace Xamarin.Forms.Xaml var rootnode = new RuntimeRootNode (new XmlType (reader.NamespaceURI, reader.Name, null), null, (IXmlNamespaceResolver)reader); XamlParser.ParseXaml (rootnode, reader); var visitorContext = new HydratationContext { - DoNotThrowOnExceptions = doNotThrow, + ExceptionHandler = doNotThrow ? e => { } : (Action<Exception>)null, }; var cvv = new CreateValuesVisitor (visitorContext); cvv.Visit ((ElementNode)rootnode, null); @@ -127,10 +131,14 @@ namespace Xamarin.Forms.Xaml static string GetXamlForType(Type type) { - string xaml = null; - //the Previewer might want to provide it's own xaml for this... let them do that - if (Xamarin.Forms.Xaml.Internals.XamlLoader.XamlFileProvider != null && (xaml = Xamarin.Forms.Xaml.Internals.XamlLoader.XamlFileProvider(type)) != null) + //the check at the end is preferred (using ResourceLoader). keep this until all the previewers are updated + +#pragma warning disable 0618 + var xaml = Internals.XamlLoader.XamlFileProvider?.Invoke(type); +#pragma warning restore 0618 + + if (xaml != null && ResourceLoader.ResourceProvider == null) return xaml; var assembly = type.GetTypeInfo().Assembly; @@ -189,7 +197,8 @@ namespace Xamarin.Forms.Xaml return null; XamlResources[type] = resourceName; - return xaml; + var alternateXaml = ResourceLoader.ResourceProvider?.Invoke(resourceName); + return alternateXaml ?? xaml; } static bool ResourceMatchesFilename(Assembly assembly, string resource, string filename) |