зеркало из https://github.com/DeGsoft/maui-linux.git
[XamlC] provide backward compat for ProvideValueTarget without Target… (#583)
* [XamlC] provide backward compat for ProvideValueTarget without TargetProperty * docs
This commit is contained in:
Родитель
1ff0db9c6f
Коммит
3ff3487d4f
|
@ -12,21 +12,19 @@ namespace Xamarin.Forms.Xaml
|
|||
{
|
||||
if (serviceProvider == null)
|
||||
throw new ArgumentNullException(nameof(serviceProvider));
|
||||
if (Key == null)
|
||||
{
|
||||
var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
|
||||
if (Key == null) {
|
||||
var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
|
||||
var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
|
||||
throw new XamlParseException("you must specify a key in {StaticResource}", lineInfo);
|
||||
}
|
||||
var valueProvider = serviceProvider.GetService(typeof (IProvideValueTarget)) as IProvideParentValues;
|
||||
var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues;
|
||||
if (valueProvider == null)
|
||||
throw new ArgumentException();
|
||||
var xmlLineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
|
||||
var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
|
||||
var xmlLineInfo = xmlLineInfoProvider != null ? xmlLineInfoProvider.XmlLineInfo : null;
|
||||
object resource = null;
|
||||
|
||||
foreach (var p in valueProvider.ParentObjects)
|
||||
{
|
||||
foreach (var p in valueProvider.ParentObjects) {
|
||||
var ve = p as VisualElement;
|
||||
var resDict = ve?.Resources ?? p as ResourceDictionary;
|
||||
if (resDict == null)
|
||||
|
@ -36,7 +34,7 @@ namespace Xamarin.Forms.Xaml
|
|||
}
|
||||
if (resource == null && Application.Current != null && Application.Current.Resources != null &&
|
||||
Application.Current.Resources.ContainsKey(Key))
|
||||
resource = Application.Current.Resources [Key];
|
||||
resource = Application.Current.Resources[Key];
|
||||
|
||||
if (resource == null)
|
||||
throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
|
||||
|
@ -44,12 +42,17 @@ namespace Xamarin.Forms.Xaml
|
|||
var bp = valueProvider.TargetProperty as BindableProperty;
|
||||
var pi = valueProvider.TargetProperty as PropertyInfo;
|
||||
var propertyType = bp?.ReturnType ?? pi?.PropertyType;
|
||||
if (propertyType == null)
|
||||
if (propertyType == null) {
|
||||
if (resource.GetType().GetTypeInfo().IsGenericType && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>) || resource.GetType().GetGenericTypeDefinition() == typeof(OnIdiom<>))) {
|
||||
// This is only there to support our backward compat story with pre 2.3.3 compiled Xaml project who was not providing TargetProperty
|
||||
var method = resource.GetType().GetRuntimeMethod("op_Implicit", new[] { resource.GetType() });
|
||||
resource = method.Invoke(resource, new[] { resource });
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
if (propertyType.IsAssignableFrom(resource.GetType()))
|
||||
return resource;
|
||||
var implicit_op = resource.GetType().GetRuntimeMethod("op_Implicit", new [] { resource.GetType() });
|
||||
//This will invoke the op_implicit on OnPlatform<>
|
||||
if (implicit_op != null && propertyType.IsAssignableFrom(implicit_op.ReturnType))
|
||||
return implicit_op.Invoke(resource, new [] { resource });
|
||||
|
||||
|
|
|
@ -137,6 +137,11 @@ namespace Xamarin.Forms.Xaml.Internals
|
|||
readonly object[] objectAndParents;
|
||||
readonly object targetProperty;
|
||||
|
||||
[Obsolete("TargetProperty is now supported, use it")]
|
||||
public SimpleValueTargetProvider(object[] objectAndParents) : this (objectAndParents, null)
|
||||
{
|
||||
}
|
||||
|
||||
public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty)
|
||||
{
|
||||
if (objectAndParents == null)
|
||||
|
|
|
@ -21,7 +21,13 @@
|
|||
<MemberType>Constructor</MemberType>
|
||||
<AssemblyInfo>
|
||||
<AssemblyVersion>1.5.0.0</AssemblyVersion>
|
||||
<AssemblyVersion>2.0.0.0</AssemblyVersion>
|
||||
</AssemblyInfo>
|
||||
<Attributes>
|
||||
<Attribute>
|
||||
<AttributeName>System.Obsolete("TargetProperty is now supported, use it")</AttributeName>
|
||||
</Attribute>
|
||||
</Attributes>
|
||||
<Parameters>
|
||||
<Parameter Name="objectAndParents" Type="System.Object[]" />
|
||||
</Parameters>
|
||||
|
|
Загрузка…
Ссылка в новой задаче