Skip to content

Commit e326d7a

Browse files
committed
fix: Update XamlFileGenerator.cs
1 parent db31092 commit e326d7a

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs

+19-22
Original file line numberDiff line numberDiff line change
@@ -1989,29 +1989,26 @@ private bool HasDescendantsWith(XamlObjectDefinition xamlObjectDefinition, Func<
19891989

19901990
var ns = GetTrimmedNamespace(xamlType.PreferredXamlNamespace); // No MarkupExtensions are defined in the framework, so we expect a user-defined namespace
19911991
INamedTypeSymbol? findType;
1992-
if (ns != xamlType.PreferredXamlNamespace)
1993-
{
1994-
// If GetTrimmedNamespace returned a different string, it's a "using:"-prefixed namespace.
1995-
// In this case, we'll have `baseTypeString` as
1996-
// the fully qualified type name.
1997-
// In this case, we go through this code path as it's much more efficient than FindType.
1998-
var baseTypeString = $"{ns}.{xamlType.Name}";
1999-
findType = _metadataHelper.FindTypeByFullName(baseTypeString + "Extension") as INamedTypeSymbol; // Support shortened syntax
2000-
findType ??= _metadataHelper.FindTypeByFullName(baseTypeString) as INamedTypeSymbol;
2001-
}
2002-
else
2003-
{
2004-
// It looks like FindType always returns null in this code path.
1992+
if (ns == xamlType.PreferredXamlNamespace)
1993+
{
1994+
// It looks like FindType always returns null in this code path.
20051995
// So, we avoid the costly call here.
2006-
return null;
2007-
}
2008-
2009-
if (findType?.Is(Generation.MarkupExtensionSymbol.Value) ?? false)
2010-
{
2011-
return findType;
2012-
}
2013-
2014-
return null;
1996+
return null;
1997+
}
1998+
1999+
// If GetTrimmedNamespace returned a different string, it's a "using:"-prefixed namespace.
2000+
// In this case, we'll have `baseTypeString` as
2001+
// the fully qualified type name.
2002+
// In this case, we go through this code path as it's much more efficient than FindType.
2003+
var baseTypeString = $"{ns}.{xamlType.Name}";
2004+
2005+
// Try finding the type with "Extension" suffix first, then without
2006+
return FindMarkupExtensionType(baseTypeString + "Extension") ?? FindMarkupExtensionType(baseTypeString);
2007+
}
2008+
2009+
private INamedTypeSymbol? FindMarkupExtensionType(string fullTypeName)
2010+
{
2011+
return _metadataHelper.FindTypeByFullName(fullTypeName) is INamedTypeSymbol type && type.Is(Generation.MarkupExtensionSymbol.Value) ? type : null;
20152012
}
20162013

20172014
private bool IsCustomMarkupExtensionType(XamlType? xamlType) =>

0 commit comments

Comments
 (0)