Skip to content

Commit

Permalink
chore: misc debug-qol changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Sep 14, 2024
1 parent 71ba1f0 commit 913a9ea
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Uno.UI/UI/Xaml/FrameworkTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected FrameworkTemplate()
=> throw new NotSupportedException("Use the factory constructors");

public FrameworkTemplate(Func<View?>? factory)
: this(null, (o, s) => factory?.Invoke())
: this(null, (o, s) => factory?.Invoke(), factory)
{
// TODO: to be removed on next major update.
// This overload simply should not exist, since the materialized members do not have the tp injected.
Expand All @@ -57,14 +57,19 @@ public FrameworkTemplate(Func<View?>? factory)

#if ENABLE_LEGACY_TEMPLATED_PARENT_SUPPORT
public FrameworkTemplate(object? owner, LegacyFrameworkTemplateBuilder? factory)
: this(owner, (o, s) => factory?.Invoke(o))
: this(owner, (o, s) => factory?.Invoke(o), factory)
{
// TODO: to be removed on next major update.
this._isLegacyTemplate = true;
}
#endif

public FrameworkTemplate(object? owner, FrameworkTemplateBuilder? factory)
: this(owner, factory, factory)
{
}

private FrameworkTemplate(object? owner, FrameworkTemplateBuilder? factory, Delegate? rawFactory)
{
InitializeBinder();

Expand All @@ -73,7 +78,12 @@ public FrameworkTemplate(object? owner, FrameworkTemplateBuilder? factory)

// Compute the hash for this template once, it will be used a lot
// in the ControlPool's internal dictionary.
_hashCode = (factory?.Target?.GetHashCode() ?? 0) ^ (factory?.Method.GetHashCode() ?? 0);
_hashCode = HashCode.Combine(rawFactory?.Target, rawFactory?.Method);
#if DEBUG
// `rawFactory` is guarantee to contains the actual factory method,
// `factory` can sometime be the lambda from the overloads
TemplateSource = $"{rawFactory?.Method.DeclaringType}.{rawFactory?.Method.Name}";
#endif

_xamlScope = ResourceResolver.CurrentScope;
}
Expand Down Expand Up @@ -160,7 +170,7 @@ public override bool Equals(object? obj)
public override int GetHashCode() => _hashCode;

#if DEBUG
public string TemplateSource => $"{_viewFactory?.Method.DeclaringType}.{_viewFactory?.Method.Name}";
public string TemplateSource { get; init; }
#endif

internal class FrameworkTemplateEqualityComparer : IEqualityComparer<FrameworkTemplate>
Expand Down

0 comments on commit 913a9ea

Please sign in to comment.