Skip to content

Commit

Permalink
Revert "[X] Ignore Parent DataType on collection (#24530)"
Browse files Browse the repository at this point in the history
This reverts commit 68524c8.

# Conflicts:
#	src/Controls/src/Xaml/XamlServiceProvider.cs
#	src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj
#	src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs
  • Loading branch information
rmarinho committed Sep 30, 2024
1 parent cff6061 commit ebe8270
Show file tree
Hide file tree
Showing 3 changed files with 342 additions and 43 deletions.
38 changes: 5 additions & 33 deletions src/Controls/src/Xaml/XamlServiceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Xml;
using Microsoft.Maui.Controls.Internals;
Expand Down Expand Up @@ -37,7 +35,7 @@ internal XamlServiceProvider(INode node, HydrationContext context)
IValueConverterProvider = defaultValueConverterProvider;

if (node is IElementNode elementNode)
Add(typeof(IXamlDataTypeProvider), new XamlDataTypeProvider(elementNode, context));
Add(typeof(IXamlDataTypeProvider), new XamlDataTypeProvider(elementNode));
}

public XamlServiceProvider() => IValueConverterProvider = defaultValueConverterProvider;
Expand Down Expand Up @@ -296,15 +294,8 @@ public string LookupNamespace(string prefix)

class XamlDataTypeProvider : IXamlDataTypeProvider
{
[RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
#if !NETSTANDARD
[RequiresDynamicCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
#endif
public XamlDataTypeProvider(IElementNode node, HydrationContext context)
public XamlDataTypeProvider(IElementNode node)
{
Context = context;


static IElementNode GetParent(IElementNode node)
{
return node switch
Expand All @@ -324,21 +315,6 @@ static bool IsBindingContextBinding(IElementNode node)
return false;
}

static bool IsBindingBaseProperty(IElementNode node, HydrationContext context)
{
if ( node.TryGetPropertyName(node.Parent, out XmlName name)
&& node.Parent is IElementNode parent
&& XamlParser.GetElementType(parent.XmlType,
new XmlLineInfo(((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition),
context.RootElement.GetType().Assembly, out var xpe) is Type parentType
&& parentType.GetRuntimeProperties().FirstOrDefault(p => p.Name == name.LocalName) is PropertyInfo propertyInfo
&& propertyInfo.PropertyType == typeof(BindingBase))
{
return true;
}
return false;
}

INode dataTypeNode = null;
IElementNode n = node as IElementNode;

Expand All @@ -355,21 +331,17 @@ static bool IsBindingBaseProperty(IElementNode node, HydrationContext context)

while (n != null)
{

if (n != skipNode && n.Properties.TryGetValue(XmlName.xDataType, out dataTypeNode))
{
break;
}
if (IsBindingBaseProperty(n, context))
{
break;
}

n = GetParent(n);
}
if (dataTypeNode is ValueNode valueNode)
BindingDataType = valueNode.Value as string;

}
public string BindingDataType { get; }
public HydrationContext Context { get; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>Microsoft.Maui.Controls.Xaml.UnitTests</AssemblyName>
<WarningLevel>4</WarningLevel>
<NoWarn>$(NoWarn);0672;0219;0414;CS0436;CS0618</NoWarn>
<WarningsNotAsErrors>$(WarningsNotAsErrors);XC0618;XC0022;XC0023;XC0045</WarningsNotAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors);XC0618;XC0022,XC0023</WarningsNotAsErrors>
<IsPackable>false</IsPackable>
<DisableMSBuildAssemblyCopyCheck>true</DisableMSBuildAssemblyCopyCheck>
</PropertyGroup>
Expand All @@ -19,7 +19,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NSubstitute" Version="$(NSubstitutePackageVersion)" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
Expand Down Expand Up @@ -54,4 +53,4 @@

<Import Project="$(MauiSrcDirectory)Maui.InTree.props" Condition=" '$(UseMaui)' != 'true' " />

</Project>
</Project>
Loading

0 comments on commit ebe8270

Please sign in to comment.