Skip to content

Commit

Permalink
fix: Exclude ResourceDictionary to improve linkability of `XamlContro…
Browse files Browse the repository at this point in the history
…lsResources`
  • Loading branch information
jeromelaban committed Aug 14, 2020
1 parent 9982157 commit 597ca36
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class BindableTypeProvidersSourceGenerator : SourceGenerator
private INamedTypeSymbol _javaObjectSymbol;
private INamedTypeSymbol _nsObjectSymbol;
private INamedTypeSymbol _nonBindableSymbol;

private INamedTypeSymbol _resourceDictionarySymbol;
private IModuleSymbol _currentModule;

public string[] AnalyzerSuppressions { get; set; }
Expand All @@ -58,7 +58,7 @@ public override void Execute(SourceGeneratorContext context)
_nsObjectSymbol = context.Compilation.GetTypeByMetadataName("Foundation.NSObject");
_stringSymbol = context.Compilation.GetTypeByMetadataName("System.String");
_nonBindableSymbol = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.Data.NonBindableAttribute");

_resourceDictionarySymbol = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.ResourceDictionary");
_currentModule = context.Compilation.SourceModule;

AnalyzerSuppressions = new string[0];
Expand Down Expand Up @@ -142,7 +142,12 @@ from type in module.GlobalNamespace.GetNamespaceTypes()
return writer.ToString();
}

private bool IsValidProvider(INamedTypeSymbol type) => type.IsLocallyPublic(_currentModule);
private bool IsValidProvider(INamedTypeSymbol type)
=> type.IsLocallyPublic(_currentModule)

// Exclude resource dictionaries for linking constraints (XamlControlsResources in particular)
// Those are not databound, so there's no need to generate providers for them.
&& !type.Is(_resourceDictionarySymbol);

private void GenerateProviderTable(IEnumerable<INamedTypeSymbol> q, IndentedStringBuilder writer)
{
Expand Down

0 comments on commit 597ca36

Please sign in to comment.