Skip to content
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

[X] Change the default value for xaml-comp #19390

Merged
merged 1 commit into from
Dec 19, 2023
Merged
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
8 changes: 4 additions & 4 deletions src/Controls/src/SourceGen/CodeBehindGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static bool TryParseXaml(SourceText text, string uid, Compilation compilation, A

if (rootClass != null)
XmlnsHelper.ParseXmlns(rootClass.Value, out rootType, out rootClrNamespace, out var rootAsm, out var targetPlatform);
else if (hasXamlCompilationProcessingInstruction)
else if (hasXamlCompilationProcessingInstruction && root.NamespaceURI == XamlParser.MauiUri)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this check to make sure the file was valid Xaml, but it ain't right, even if it works

{
rootClrNamespace = "__XamlGeneratedCode__";
rootType = $"__Type{uid}";
Expand Down Expand Up @@ -325,13 +325,13 @@ static bool GetXamlCompilationProcessingInstruction(XmlDocument xmlDoc)
{
var instruction = xmlDoc.SelectSingleNode("processing-instruction('xaml-comp')") as XmlProcessingInstruction;
if (instruction == null)
return false;
return true;

var parts = instruction.Data.Split(' ', '=');
var indexOfCompile = Array.IndexOf(parts, "compile");
if (indexOfCompile != -1)
return parts[indexOfCompile + 1].Trim('"', '\'').Equals("true", StringComparison.OrdinalIgnoreCase);
return false;
return !parts[indexOfCompile + 1].Trim('"', '\'').Equals("false", StringComparison.OrdinalIgnoreCase);
return true;
}

static IEnumerable<(string name, string type, string accessModifier)> GetNamedFields(XmlNode root, XmlNamespaceManager nsmgr, Compilation compilation, AssemblyCaches caches, CancellationToken cancellationToken)
Expand Down
11 changes: 6 additions & 5 deletions src/Controls/tests/Xaml.UnitTests/CecilExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,28 @@ EmbeddedResource GetResource(string name)
"IsCompiledDefault",
"X2006Namespace",
"X2009Primitives",
"Validation.MissingXClass",
};

[Test, TestCaseSource(nameof(IsXamlTrueSource))]
public void IsXamlTrue(string name)
{
var resource = GetResource(name);
Assert.IsTrue(resource.IsXaml(new XamlCache(), assembly.MainModule, out string className), $"IsXaml should return true for '{name}'.");
Assert.AreEqual(className, $"{testNamespace}.{name}"); // Test cases x:Class matches the file name
if (!className.StartsWith("__XamlGeneratedCode__"))
Assert.AreEqual(className, $"{testNamespace}.{name}"); // Test cases x:Class matches the file name
}

static string[] IsXamlFalseSource = new[]
{
"Validation.MissingXClass",
"Validation.NotXaml",
};

};
[Test, TestCaseSource(nameof(IsXamlFalseSource))]
public void IsXamlFalse(string name)
{
var resource = GetResource(name);
Assert.IsFalse(resource.IsXaml(new XamlCache(), assembly.MainModule, out _), $"IsXaml should return false for '{name}'.");
}
}
}
}
2 changes: 2 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Gh13209.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public Gh13209(bool useCompiledXaml)
[TestFixture]
class Tests
{
[TearDown] public void TearDown() => ResourceDictionary.ClearCache();

[TestCase(true), TestCase(false)]
public void RdWithSource(bool useCompiledXaml)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Maui.Controls.Core.UnitTests;
using Microsoft.Maui.Graphics;
using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace Microsoft.Maui.Controls.Xaml.UnitTests
{
Expand Down Expand Up @@ -48,7 +49,7 @@ public void XRIDIsGeneratedForRDWithoutCodeBehind()
var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(asm, "AppResources/Colors.xaml");
Assert.That(resourceId, Is.Not.Null);
var type = XamlResourceIdAttribute.GetTypeForResourceId(asm, resourceId);
Assert.That(type, Is.Null);
Assert.That(type.Name, Does.StartWith("__Type")); //xaml-comp defult to true, so this is an autogenerated code behind
}

[Test]
Expand Down
Loading