Skip to content

[X] global xmlns #28969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Microsoft.Maui-vscode.sln
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITest.Analyzers", "src\Tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Controls.Sample.Embedding", "src\Controls\samples\Controls.Sample.Embedding\Maui.Controls.Sample.Embedding.csproj", "{4ADCBA87-30DB-44F5-85E9-94A4F4132FD9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGen.UnitTests", "src\Controls\tests\SourceGen.UnitTests\SourceGen.UnitTests.csproj", "{A426B2FC-F012-436B-BDD9-BEC0025DB96B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -539,6 +541,10 @@ Global
{4ADCBA87-30DB-44F5-85E9-94A4F4132FD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4ADCBA87-30DB-44F5-85E9-94A4F4132FD9}.Release|Any CPU.Build.0 = Release|Any CPU
{4ADCBA87-30DB-44F5-85E9-94A4F4132FD9}.Release|Any CPU.Deploy.0 = Release|Any CPU
{A426B2FC-F012-436B-BDD9-BEC0025DB96B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A426B2FC-F012-436B-BDD9-BEC0025DB96B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A426B2FC-F012-436B-BDD9-BEC0025DB96B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A426B2FC-F012-436B-BDD9-BEC0025DB96B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -636,6 +642,7 @@ Global
{0048EA9A-D751-4576-A2BB-2A37BFB385A5} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{DA001142-4777-4EDE-97D5-B1AC08162F99} = {7AC28763-9C68-4BF9-A1BA-25CBFFD2D15C}
{4ADCBA87-30DB-44F5-85E9-94A4F4132FD9} = {E1082E26-D700-4127-9329-66D673FD2D55}
{A426B2FC-F012-436B-BDD9-BEC0025DB96B} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public XmlnsDefinitionAttribute (string xmlNamespace, string clrNamespace);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string xmlNamespace, string clrNamespace) cil managed" />
<MemberSignature Language="C#" Value="public XmlnsDefinitionAttribute (string xmlNamespace, string target);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string xmlNamespace, string target) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Maui.Controls.XmlnsDefinitionAttribute.#ctor(System.String,System.String)" />
<MemberSignature Language="F#" Value="new Microsoft.Maui.Controls.XmlnsDefinitionAttribute : string * string -&gt; Microsoft.Maui.Controls.XmlnsDefinitionAttribute" Usage="new Microsoft.Maui.Controls.XmlnsDefinitionAttribute (xmlNamespace, clrNamespace)" />
<MemberType>Constructor</MemberType>
Expand All @@ -35,11 +35,11 @@
</AssemblyInfo>
<Parameters>
<Parameter Name="xmlNamespace" Type="System.String" />
<Parameter Name="clrNamespace" Type="System.String" />
<Parameter Name="target" Type="System.String" />
</Parameters>
<Docs>
<param name="xmlNamespace">To be added.</param>
<param name="clrNamespace">To be added.</param>
<param name="target">To be added.</param>
</Docs>
</Member>
<Member MemberName="AssemblyName">
Expand Down Expand Up @@ -74,6 +74,22 @@
<Docs>
</Docs>
</Member>
<Member MemberName="Target">
<MemberSignature Language="C#" Value="public string Target { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Target" />
<MemberSignature Language="DocId" Value="P:Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace" />
<MemberSignature Language="F#" Value="member this.ClrNamespace : string" Usage="Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Maui.Controls.Core</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
</Docs>
</Member>
<Member MemberName="XmlNamespace">
<MemberSignature Language="C#" Value="public string XmlNamespace { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string XmlNamespace" />
Expand Down
33 changes: 24 additions & 9 deletions src/Controls/src/Build.Tasks/XmlTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.Maui.Controls.Build.Tasks
{
static class XmlTypeExtensions
{
static readonly string _xmlnsDefinitionName = typeof(XmlnsDefinitionAttribute).FullName;

static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDefinition module)
{
var xmlnsDefinitions = new List<XmlnsDefinitionAttribute>();
Expand All @@ -18,17 +20,12 @@ static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDef
{
// Search for the attribute in the assemblies being
// referenced.
GatherXmlnsDefinitionAttributes(xmlnsDefinitions, module.Assembly, module.Assembly);

foreach (var asmRef in module.AssemblyReferences)
{
var asmDef = module.AssemblyResolver.Resolve(asmRef);
foreach (var ca in asmDef.CustomAttributes)
{
if (ca.AttributeType.FullName == typeof(XmlnsDefinitionAttribute).FullName)
{
var attr = GetXmlnsDefinition(ca, asmDef);
xmlnsDefinitions.Add(attr);
}
}
GatherXmlnsDefinitionAttributes(xmlnsDefinitions, asmDef, module.Assembly);
}
}
else
Expand All @@ -50,6 +47,22 @@ static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDef
return xmlnsDefinitions;
}

static void GatherXmlnsDefinitionAttributes(List<XmlnsDefinitionAttribute> xmlnsDefinitions, AssemblyDefinition asmDef, AssemblyDefinition currentAssembly)
{
foreach (var ca in asmDef.CustomAttributes)
{
if (ca.AttributeType.FullName == _xmlnsDefinitionName)
{
var attr = GetXmlnsDefinition(ca, asmDef);
//only add globalxmlns definition from the current assembly
if (attr.XmlNamespace == XamlParser.MauiGlobal
&& asmDef != currentAssembly)
continue;
xmlnsDefinitions.Add(attr);
}
}
}

public static TypeReference GetTypeReference(XamlCache cache, string typeName, ModuleDefinition module, BaseNode node, bool expandToExtension = true)
{
try
Expand All @@ -76,6 +89,8 @@ public static bool TryGetTypeReference(this XmlType xmlType, XamlCache cache, Mo

TypeReference type = xmlType.GetTypeReference(xmlnsDefinitions, module.Assembly.Name.Name, (typeInfo) =>
{
if (typeInfo.clrNamespace.StartsWith("http")) //aggregated xmlns, might result in a typeload exception
return null;
string typeName = typeInfo.typeName.Replace('+', '/'); //Nested types
var type = module.GetTypeDefinition(cache, (typeInfo.assemblyName, typeInfo.clrNamespace, typeName));
if (type is not null && type.IsPublicOrVisibleInternal(module))
Expand All @@ -97,7 +112,7 @@ public static TypeReference GetTypeReference(this XmlType xmlType, XamlCache cac
throw new BuildException(BuildExceptionCode.TypeResolution, xmlInfo, null, $"{xmlType.NamespaceUri}:{xmlType.Name}");
}

public static XmlnsDefinitionAttribute GetXmlnsDefinition(this CustomAttribute ca, AssemblyDefinition asmDef)
static XmlnsDefinitionAttribute GetXmlnsDefinition(this CustomAttribute ca, AssemblyDefinition asmDef)
{
var attr = new XmlnsDefinitionAttribute(
ca.ConstructorArguments[0].Value as string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.AssemblyName.set -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string target) -> void
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.Prefix.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlnsPrefixAttribute(string xmlNamespace, string prefix) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ static readonly Microsoft.Maui.Controls.TitleBar.SubtitleProperty -> Microsoft.M
static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target.get -> string
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.AssemblyName.set -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string target) -> void
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.Prefix.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlnsPrefixAttribute(string xmlNamespace, string prefix) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,4 @@ virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.Up
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.SetNeedsLayout() -> void
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<TElement>.MovedToWindow() -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target.get -> string
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.AssemblyName.set -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string target) -> void
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.Prefix.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlnsPrefixAttribute(string xmlNamespace, string prefix) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,5 @@ virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewDelegator2<TItemsView,
virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.UpdateLayout() -> void
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.SetNeedsLayout() -> void
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<TElement>.MovedToWindow() -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<TElement>.MovedToWindow() -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target.get -> string
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.AssemblyName.set -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string target) -> void
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.Prefix.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlnsPrefixAttribute(string xmlNamespace, string prefix) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ static readonly Microsoft.Maui.Controls.TitleBar.SubtitleProperty -> Microsoft.M
static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target.get -> string
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.AssemblyName.set -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string target) -> void
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.Prefix.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlnsPrefixAttribute(string xmlNamespace, string prefix) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ static readonly Microsoft.Maui.Controls.TitleBar.SubtitleProperty -> Microsoft.M
static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target.get -> string
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.AssemblyName.set -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string target) -> void
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.Prefix.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlnsPrefixAttribute(string xmlNamespace, string prefix) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ static readonly Microsoft.Maui.Controls.TitleBar.SubtitleProperty -> Microsoft.M
static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target.get -> string
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.AssemblyName.set -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.ClrNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) -> void
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.XmlnsDefinitionAttribute(string xmlNamespace, string target) -> void
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.Prefix.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlNamespace.get -> string
~Microsoft.Maui.Controls.XmlnsPrefixAttribute.XmlnsPrefixAttribute(string xmlNamespace, string prefix) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Microsoft.Maui.Controls.StyleableElement.Style.get -> Microsoft.Maui.Controls.St
~Microsoft.Maui.Controls.WebViewProcessTerminatedEventArgs.PlatformArgs.get -> Microsoft.Maui.Controls.PlatformWebViewProcessTerminatedEventArgs
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.XmlnsDefinitionAttribute.Target.get -> string
~override Microsoft.Maui.Controls.ShellContent.OnPropertyChanged(string propertyName = null) -> void
*REMOVED*~static Microsoft.Maui.Controls.Application.ControlsApplicationMapper -> Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IApplication, Microsoft.Maui.Handlers.ApplicationHandler>
~static Microsoft.Maui.Controls.Brush.DarkGrey.get -> Microsoft.Maui.Controls.SolidColorBrush
Expand Down
Loading
Loading