Skip to content

Commit

Permalink
[X] Change the default value for xaml-comp
Browse files Browse the repository at this point in the history
The default value for the xaml-comp processing instruction used to be
false, meaning the a XAML ResourceDictionary without code-behind wasn't
compiled by XamlC unless the <?xaml-comp compile="true" ?> processing
instruction was specified.

From now on, we will compile all XAML-only RD, unless the <?xaml-comp
compile="false" ?> is set.

Thsi will help with performance and trimming
  • Loading branch information
StephaneDelcroix committed Dec 13, 2023
1 parent 9b99433 commit 1a87a17
Showing 1 changed file with 4 additions and 4 deletions.
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)
{
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

0 comments on commit 1a87a17

Please sign in to comment.