Skip to content

Commit

Permalink
fix: Avoid possible exception in hot-reload
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Oct 27, 2023
1 parent 7b17ad6 commit e816bf5
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1464,11 +1464,22 @@ private bool BuildDefaultStylesRegistration(IIndentedStringBuilder writer, XamlM

using (writer.BlockInvariant("public static void RegisterDefaultStyles_{0}()", _fileUniqueId))
{
var instance = _isHotReloadEnabled
? $"((dynamic) Instance)"
: $"(({SingletonClassName})Instance)";

writer.AppendLineInvariantIndented("{0}.RegisterDefaultStyles_{1}_Core();", instance, _fileUniqueId);
if (_isHotReloadEnabled)
{
writer.AppendLineInvariantIndented("var instance = Instance;");
using (writer.BlockInvariant("if (instance is {0} original)", SingletonClassName))
{
writer.AppendLineInvariantIndented("original.RegisterDefaultStyles_{1}_Core();", SingletonClassName, _fileUniqueId);
}
using (writer.BlockInvariant("else"))
{
writer.AppendLineInvariantIndented("instance?.GetType()?.GetMethod(\"RegisterDefaultStyles_{0}_Core\", global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic)?.Invoke(instance, null);", _fileUniqueId);
}
}
else
{
writer.AppendLineInvariantIndented("(({0})Instance).RegisterDefaultStyles_{1}_Core();", SingletonClassName, _fileUniqueId);
}
}

using (writer.BlockInvariant("private void RegisterDefaultStyles_{0}_Core()", _fileUniqueId))
Expand Down

0 comments on commit e816bf5

Please sign in to comment.