-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18880 from ramezgerges/xamlgenerator_syntax_error…
…_xuid fix(xamlgenerator): fix syntax error when using x:Uid
- Loading branch information
Showing
6 changed files
with
236 additions
and
4 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_Xuid.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis.Testing; | ||
using Uno.UI.SourceGenerators.Tests.Verifiers; | ||
|
||
namespace Uno.UI.SourceGenerators.Tests.XamlCodeGeneratorTests; | ||
|
||
using Verify = XamlSourceGeneratorVerifier; | ||
|
||
[TestClass] | ||
public class Given_Xuid | ||
{ | ||
[TestMethod] | ||
public async Task When_Xuid_Basic() | ||
{ | ||
var xamlFile = new XamlFile("ContentDialog1.xaml", """ | ||
<ContentDialog | ||
x:Class="TestRepro.XuidGeneratorError" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Uid="XuidGeneratorErrorUid"> | ||
</ContentDialog> | ||
"""); | ||
|
||
var resourceFile = new ResourceFile("en", "Resources.resw", | ||
""" | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<data name="XuidGeneratorErrorUid.PrimaryButtonText" xml:space="preserve"> | ||
<value>SomeValue</value> | ||
</data> | ||
</root> | ||
"""); | ||
|
||
var test = new Verify.Test([xamlFile], [resourceFile]) | ||
{ | ||
TestState = | ||
{ | ||
Sources = | ||
{ | ||
""" | ||
using Microsoft.UI.Xaml.Controls; | ||
namespace TestRepro; | ||
public sealed partial class XuidGeneratorError : ContentDialog | ||
{ | ||
public XuidGeneratorError() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
""" | ||
} | ||
}, | ||
ReferenceAssemblies = ReferenceAssemblies.Net.Net80Android.AddPackages(ImmutableArray.Create(new PackageIdentity("Uno.WinUI", "5.0.118"))), | ||
DisableBuildReferences = true, | ||
}.AddGeneratedSources(); | ||
|
||
await test.RunAsync(); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...neratorTests/Out/WXB/XamlCodeGenerator_ContentDialog1_4483f06b3f5899cc3b98f0345eeea8e5.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// <autogenerated /> | ||
#pragma warning disable CS0114 | ||
#pragma warning disable CS0108 | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Uno.UI; | ||
using Uno.UI.Xaml; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Documents; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Media.Animation; | ||
using Microsoft.UI.Xaml.Shapes; | ||
using Windows.UI.Text; | ||
using Uno.Extensions; | ||
using Uno; | ||
using Uno.UI.Helpers; | ||
using Uno.UI.Helpers.Xaml; | ||
using MyProject; | ||
|
||
#if __ANDROID__ | ||
using _View = Android.Views.View; | ||
#elif __IOS__ | ||
using _View = UIKit.UIView; | ||
#elif __MACOS__ | ||
using _View = AppKit.NSView; | ||
#else | ||
using _View = Microsoft.UI.Xaml.UIElement; | ||
#endif | ||
|
||
namespace TestRepro | ||
{ | ||
partial class XuidGeneratorError : global::Microsoft.UI.Xaml.Controls.ContentDialog | ||
{ | ||
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
private const string __baseUri_prefix_ContentDialog1_4483f06b3f5899cc3b98f0345eeea8e5 = "ms-appx:///TestProject/"; | ||
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
private const string __baseUri_ContentDialog1_4483f06b3f5899cc3b98f0345eeea8e5 = "ms-appx:///TestProject/"; | ||
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); | ||
private void InitializeComponent() | ||
{ | ||
NameScope.SetNameScope(this, __nameScope); | ||
var __that = this; | ||
base.IsParsing = true; | ||
// Source 0\ContentDialog1.xaml (Line 1:2) | ||
; | ||
|
||
PrimaryButtonText = global::Uno.UI.Helpers.MarkupHelper.GetResourceStringForXUid("TestProject/Resources", "XuidGeneratorErrorUid/PrimaryButtonText"); | ||
|
||
this | ||
.GenericApply(((c0) => | ||
{ | ||
// Source 0\ContentDialog1.xaml (Line 1:2) | ||
|
||
// WARNING Property c0.base does not exist on {http://schemas.microsoft.com/winfx/2006/xaml/presentation}ContentDialog, the namespace is http://www.w3.org/XML/1998/namespace. This error was considered irrelevant by the XamlFileGenerator | ||
} | ||
)) | ||
.GenericApply(((c1) => | ||
{ | ||
// Class TestRepro.XuidGeneratorError | ||
global::Uno.UI.Helpers.MarkupHelper.SetXUid(c1, "XuidGeneratorErrorUid"); | ||
global::Uno.UI.FrameworkElementHelper.SetBaseUri(c1, __baseUri_ContentDialog1_4483f06b3f5899cc3b98f0345eeea8e5); | ||
c1.CreationComplete(); | ||
} | ||
)) | ||
; | ||
OnInitializeCompleted(); | ||
|
||
} | ||
partial void OnInitializeCompleted(); | ||
} | ||
} | ||
namespace MyProject | ||
{ | ||
static class ContentDialog1_4483f06b3f5899cc3b98f0345eeea8e5XamlApplyExtensions | ||
{ | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...enerators.Tests/XamlCodeGeneratorTests/Out/WXB/XamlCodeGenerator_GlobalStaticResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// <autogenerated /> | ||
namespace MyProject | ||
{ | ||
/// <summary> | ||
/// Contains all the static resources defined for the application | ||
/// </summary> | ||
public sealed partial class GlobalStaticResources | ||
{ | ||
static bool _initialized; | ||
private static bool _stylesRegistered; | ||
private static bool _dictionariesRegistered; | ||
internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ { get; } = new global::Uno.UI.Xaml.XamlParseContext() | ||
{ | ||
AssemblyName = "TestProject", | ||
} | ||
; | ||
|
||
static GlobalStaticResources() | ||
{ | ||
Initialize(); | ||
} | ||
public static void Initialize() | ||
{ | ||
if (!_initialized) | ||
{ | ||
_initialized = true; | ||
global::Uno.UI.GlobalStaticResources.Initialize(); | ||
global::Uno.UI.Toolkit.GlobalStaticResources.Initialize(); | ||
global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles(); | ||
global::Uno.UI.Toolkit.GlobalStaticResources.RegisterDefaultStyles(); | ||
global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource(); | ||
global::Uno.UI.Toolkit.GlobalStaticResources.RegisterResourceDictionariesBySource(); | ||
} | ||
} | ||
public static void RegisterDefaultStyles() | ||
{ | ||
if(!_stylesRegistered) | ||
{ | ||
_stylesRegistered = true; | ||
RegisterDefaultStyles_ContentDialog1_4483f06b3f5899cc3b98f0345eeea8e5(); | ||
} | ||
} | ||
// Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources | ||
public static void RegisterResourceDictionariesBySource() | ||
{ | ||
if(!_dictionariesRegistered) | ||
{ | ||
_dictionariesRegistered = true; | ||
} | ||
} | ||
// Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources | ||
internal static void RegisterResourceDictionariesBySourceLocal() | ||
{ | ||
} | ||
static partial void RegisterDefaultStyles_ContentDialog1_4483f06b3f5899cc3b98f0345eeea8e5(); | ||
|
||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...enerators.Tests/XamlCodeGeneratorTests/Out/WXB/XamlCodeGenerator_LocalizationResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// <auto-generated /> | ||
[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "True")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters