Skip to content

Commit

Permalink
fix(hr): Restore udage of cnomua for resource dictionnaries
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Dec 10, 2024
1 parent 4810298 commit 8326dd2
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace MyProject
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
public sealed partial class GlobalStaticResources
{
static bool _initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace MyProject
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
public sealed partial class GlobalStaticResources
{
static bool _initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace MyProject
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
public sealed partial class GlobalStaticResources
{
static bool _initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace MyProject
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
public sealed partial class GlobalStaticResources
{
static bool _initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace MyProject
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
public sealed partial class GlobalStaticResources
{
static bool _initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace MyProject
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
public sealed partial class GlobalStaticResources
{
static bool _initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

namespace TestNamespace
{
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
public sealed partial class TestClass : global::Microsoft.UI.Xaml.ResourceDictionary
{
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
Expand All @@ -58,6 +59,9 @@ public sealed partial class GlobalStaticResources
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_MyDictionary_b7707bcf1e73425b710b6a5d04177088 = "ms-appx:///TestProject/";
// This non-static inner class is a means of reducing size of AOT compilations by avoiding many accesses to static members from a static callsite, which adds costly class initializer checks each time.
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
internal string __MyDictionary_b7707bcf1e73425b710b6a5d04177088_checksum() => "0006bfa967d7b0e0bdb0aa951326268f007434d5";
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
internal sealed class ResourceDictionarySingleton__MyDictionary_b7707bcf1e73425b710b6a5d04177088 : global::Uno.UI.IXamlResourceDictionaryProvider
{
private static global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ private SourceText GenerateGlobalResources(IEnumerable<XamlFileDefinition> files
writer.AppendLineIndented("/// Contains all the static resources defined for the application");
writer.AppendLineIndented("/// </summary>");

if (_isHotReloadEnabled)
{
writer.AppendLineIndented("[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]");
}

using (writer.BlockInvariant("public sealed partial class GlobalStaticResources"))
{
writer.AppendLineIndented("static bool _initialized;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,16 @@ IDisposable WrapSingleton()
{
writer.AppendLineIndented("// This non-static inner class is a means of reducing size of AOT compilations by avoiding many accesses to static members from a static callsite, which adds costly class initializer checks each time.");

if (_isHotReloadEnabled)
{
// Create a public member to avoid having to remove all unused member warnings
// The member is a method to avoid this error: error ENC0011: Updating the initializer of const field requires restarting the application.
writer.AppendLineIndented("[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]");
writer.AppendLineIndented($"internal string __{_fileDefinition.UniqueID}_checksum() => \"{_fileDefinition.Checksum}\";");

writer.AppendLineIndented("[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]");
}

var block = writer.BlockInvariant("internal sealed class {0} : {1}", SingletonClassName, DictionaryProviderInterfaceName);
_isInSingletonInstance = true;
return new DisposableAction(() =>
Expand Down Expand Up @@ -1694,6 +1704,11 @@ private void BuildResourceDictionaryBackingClass(IIndentedStringBuilder writer,

using (writer.BlockInvariant("namespace {0}", className.Namespace))
{
if (_isHotReloadEnabled)
{
writer.AppendLineIndented("[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]");
}

using (writer.BlockInvariant("public sealed partial class {0} : {1}", className.ClassName, controlBaseType.GetFullyQualifiedTypeIncludingGlobal()))
{
BuildBaseUri(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Threading;
using Uno.Diagnostics.UI;
using Uno.Foundation.Logging;

#if HAS_UNO_WINUI
using Uno.UI.RemoteControl.HotReload.Messages;
Expand Down Expand Up @@ -138,7 +139,14 @@ private void NotifyStatusChanged()
var status = BuildStatus();

Current = status;
owner.StatusChanged?.Invoke(this, status);
try
{
owner.StatusChanged?.Invoke(this, status);
}
catch (Exception error)
{
this.Log().Error("Failed to notify the status changed.", error);
}
}

private Status BuildStatus()
Expand Down

0 comments on commit 8326dd2

Please sign in to comment.