Reputation: 61
Given an INamedTypeSymbol of a WPF Window, I can't seem to obtain a ISymbol for the members that are defined in XAML (and are then compiled as part of the auto-generated .g.cs file).
To reproduce the problem I'm having,
<TextBlock Name="tb1"/>
to MainWindow.xamlprivate async void Compile()
{
var workspace = MSBuildWorkspace.Create();
workspace.LoadMetadataForReferencedProjects = true;
var solution = await workspace.OpenSolutionAsync(@"..\..\WpfApp1.Sln");
var project = solution.Projects.Single();
// this doesn't help
project = project.WithCompilationOptions(project.CompilationOptions.WithMetadataImportOptions(MetadataImportOptions.All));
var comp = await project.GetCompilationAsync();
INamedTypeSymbol mainWindow = comp.GetTypeByMetadataName(GetType().FullName);
var members = mainWindow.GetMembers();
Debug.Assert(members.Any(m => m.Name == nameof(tb1)));
}
As you can see, the assertion fails, and I cannot seem to find the ISymbol that represents the "tb1" member field.
members.Length == 2; // true
members[0].Name == ".ctor" // true
members[1].Name == "Compile" // true
How can I get tb1 without resorting to setting x:FieldModifier="public"
on the TextBlock
?
Upvotes: 1
Views: 104