Skip to content

Commit 1a262a8

Browse files
committed
Disable warning using pragma instead of attribute
1 parent 5407a15 commit 1a262a8

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/Controls/src/SourceGen/CodeBehindGenerator.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,9 @@ static void GenerateXamlCodeBehind(XamlProjectItem? xamlItem, Compilation compil
358358

359359
sb.AppendLine("\t\tprivate void InitializeComponent()");
360360
sb.AppendLine("\t\t{");
361-
sb.AppendLine("\t\t\t[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"TrimAnalysis\", \"IL2026:RequiresUnreferencedCode\",");
362-
sb.AppendLine("\t\t\t\tJustification = \"By default, Xaml compilation replaces the body of InitializeComponent, so LoadFromXaml will never be called in production builds.\")]");
363-
sb.AppendLine("\t\t\tvoid LoadFromXaml()");
364-
sb.AppendLine("\t\t\t{");
365-
sb.AppendLine($"\t\t\t\tglobal::Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml(this, typeof({rootType}));");
366-
sb.AppendLine("\t\t\t}");
367-
sb.AppendLine();
368-
sb.AppendLine($"\t\t\tLoadFromXaml();");
361+
sb.AppendLine("#pragma warning disable IL2026 // The body of InitializeComponent will be replaced by XamlC so LoadFromXaml will never be called in production builds");
362+
sb.AppendLine($"\t\t\tglobal::Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml(this, typeof({rootType}));");
363+
sb.AppendLine("#pragma warning restore IL2026");
369364

370365
if (namedFields != null)
371366
{

0 commit comments

Comments
 (0)