summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-02-13 09:08:21 +0100
committerGitHub <noreply@github.com>2017-02-13 09:08:21 +0100
commitd108dfe17652d3f6a18bf76d0b7f955b74244998 (patch)
tree08e09945ac6fb1caf1933a84ae775f0cc6be1ff9 /Xamarin.Forms.Xaml
parent7ffc19b2b5b70f32a8d865573824da29249ebf7a (diff)
downloadxamarin-forms-d108dfe17652d3f6a18bf76d0b7f955b74244998.tar.gz
xamarin-forms-d108dfe17652d3f6a18bf76d0b7f955b74244998.tar.bz2
xamarin-forms-d108dfe17652d3f6a18bf76d0b7f955b74244998.zip
[XamlC] compiled TypeExtension (#739)
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/MarkupExtensions/StaticExtension.cs1
-rw-r--r--Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs15
-rw-r--r--Xamarin.Forms.Xaml/MarkupExtensions/TypeExtension.cs7
3 files changed, 17 insertions, 6 deletions
diff --git a/Xamarin.Forms.Xaml/MarkupExtensions/StaticExtension.cs b/Xamarin.Forms.Xaml/MarkupExtensions/StaticExtension.cs
index 8de0ebf4..418f2551 100644
--- a/Xamarin.Forms.Xaml/MarkupExtensions/StaticExtension.cs
+++ b/Xamarin.Forms.Xaml/MarkupExtensions/StaticExtension.cs
@@ -6,6 +6,7 @@ using System.Xml;
namespace Xamarin.Forms.Xaml
{
[ContentProperty(nameof(Member))]
+ [ProvideCompiled("Xamarin.Forms.Build.Tasks.StaticExtension")]
public class StaticExtension : IMarkupExtension
{
public string Member { get; set; }
diff --git a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
index 34f1c569..fc00d308 100644
--- a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
+++ b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
@@ -1,5 +1,6 @@
using System;
using System.Reflection;
+using System.Xml;
namespace Xamarin.Forms.Xaml
{
@@ -32,9 +33,7 @@ namespace Xamarin.Forms.Xaml
if (resDict.TryGetMergedValue(Key, out resource))
break;
}
- if (resource == null && (Application.Current == null || Application.Current.Resources == null ||
- !Application.Current.Resources.TryGetMergedValue(Key, out resource)))
- throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
+ resource = resource ?? GetApplicationLevelResource(Key, xmlLineInfo);
var bp = valueProvider.TargetProperty as BindableProperty;
var pi = valueProvider.TargetProperty as PropertyInfo;
@@ -55,5 +54,13 @@ namespace Xamarin.Forms.Xaml
return resource;
}
+
+ internal object GetApplicationLevelResource(string key, IXmlLineInfo xmlLineInfo)
+ {
+ object resource;
+ if (Application.Current == null || Application.Current.Resources == null || !Application.Current.Resources.TryGetMergedValue(Key, out resource))
+ throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
+ return resource;
+ }
}
-}
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml/MarkupExtensions/TypeExtension.cs b/Xamarin.Forms.Xaml/MarkupExtensions/TypeExtension.cs
index f4bbf842..ae6b8f37 100644
--- a/Xamarin.Forms.Xaml/MarkupExtensions/TypeExtension.cs
+++ b/Xamarin.Forms.Xaml/MarkupExtensions/TypeExtension.cs
@@ -2,15 +2,18 @@ using System;
namespace Xamarin.Forms.Xaml
{
- [ContentProperty("TypeName")]
+ [ContentProperty(nameof(TypeName))]
+ [ProvideCompiled("Xamarin.Forms.Build.Tasks.TypeExtension")]
public class TypeExtension : IMarkupExtension<Type>
{
public string TypeName { get; set; }
public Type ProvideValue(IServiceProvider serviceProvider)
{
+ if (string.IsNullOrEmpty(TypeName))
+ throw new InvalidOperationException("TypeName isn't set.");
if (serviceProvider == null)
- throw new ArgumentNullException("serviceProvider");
+ throw new ArgumentNullException(nameof(serviceProvider));
var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver;
if (typeResolver == null)
throw new ArgumentException("No IXamlTypeResolver in IServiceProvider");