Skip to content

fix: Ensure that MarkupExtension search behavior is consistent with winui #19838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1988,30 +1988,26 @@ private bool HasDescendantsWith(XamlObjectDefinition xamlObjectDefinition, Func<
}

var ns = GetTrimmedNamespace(xamlType.PreferredXamlNamespace); // No MarkupExtensions are defined in the framework, so we expect a user-defined namespace
INamedTypeSymbol? findType;
if (ns != xamlType.PreferredXamlNamespace)
{
// If GetTrimmedNamespace returned a different string, it's a "using:"-prefixed namespace.
// In this case, we'll have `baseTypeString` as
// the fully qualified type name.
// In this case, we go through this code path as it's much more efficient than FindType.
var baseTypeString = $"{ns}.{xamlType.Name}";
findType = _metadataHelper.FindTypeByFullName(baseTypeString) as INamedTypeSymbol;
findType ??= _metadataHelper.FindTypeByFullName(baseTypeString + "Extension") as INamedTypeSymbol; // Support shortened syntax
}
else
if (ns == xamlType.PreferredXamlNamespace)
{
// It looks like FindType always returns null in this code path.
// So, we avoid the costly call here.
return null;
}

if (findType?.Is(Generation.MarkupExtensionSymbol.Value) ?? false)
{
return findType;
}
// If GetTrimmedNamespace returned a different string, it's a "using:"-prefixed namespace.
// In this case, we'll have `baseTypeString` as
// the fully qualified type name.
// In this case, we go through this code path as it's much more efficient than FindType.
var baseTypeString = $"{ns}.{xamlType.Name}";

return null;
// Try finding the type with "Extension" suffix first, then without
return FindMarkupExtensionType(baseTypeString + "Extension") ?? FindMarkupExtensionType(baseTypeString);
}

private INamedTypeSymbol? FindMarkupExtensionType(string fullTypeName)
{
return _metadataHelper.FindTypeByFullName(fullTypeName) is INamedTypeSymbol type && type.Is(Generation.MarkupExtensionSymbol.Value) ? type : null;
}

private bool IsCustomMarkupExtensionType(XamlType? xamlType) =>
Expand Down
Loading