mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
C# Add missing Windows Forms implicit usings
This commit is contained in:
@@ -116,8 +116,16 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
bool.TryParse(webViewExtractionOption, out var shouldExtractWebViews) &&
|
||||
shouldExtractWebViews)
|
||||
{
|
||||
CompilationInfos.Add(("WebView extraction enabled", "1"));
|
||||
GenerateSourceFilesFromWebViews(allNonBinaryFiles);
|
||||
}
|
||||
else
|
||||
{
|
||||
CompilationInfos.Add(("WebView extraction enabled", "0"));
|
||||
}
|
||||
|
||||
CompilationInfos.Add(("UseWPF set", fileContent.UseWpf ? "1" : "0"));
|
||||
CompilationInfos.Add(("UseWindowsForms set", fileContent.UseWindowsForms ? "1" : "0"));
|
||||
|
||||
GenerateSourceFileFromImplicitUsings();
|
||||
|
||||
@@ -434,6 +442,11 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
"Microsoft.Extensions.DependencyInjection", "Microsoft.Extensions.Hosting", "Microsoft.Extensions.Logging" });
|
||||
}
|
||||
|
||||
if (fileContent.UseWindowsForms)
|
||||
{
|
||||
usings.UnionWith(new[] { "System.Drawing", "System.Windows.Forms" });
|
||||
}
|
||||
|
||||
usings.UnionWith(fileContent.CustomImplicitUsings);
|
||||
|
||||
logger.LogInfo($"Generating source file for implicit usings. Namespaces: {string.Join(", ", usings.OrderBy(u => u))}");
|
||||
|
||||
@@ -61,6 +61,28 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
}
|
||||
}
|
||||
|
||||
private bool useWpf = false;
|
||||
|
||||
public bool UseWpf
|
||||
{
|
||||
get
|
||||
{
|
||||
initialize.Run();
|
||||
return useWpf;
|
||||
}
|
||||
}
|
||||
|
||||
private bool useWindowsForms = false;
|
||||
|
||||
public bool UseWindowsForms
|
||||
{
|
||||
get
|
||||
{
|
||||
initialize.Run();
|
||||
return useWindowsForms;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isLegacyProjectStructureUsed = false;
|
||||
|
||||
public bool IsLegacyProjectStructureUsed
|
||||
@@ -173,6 +195,14 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
|| line.Contains("<ImplicitUsings>enable</ImplicitUsings>".AsSpan(), StringComparison.Ordinal)
|
||||
|| line.Contains("<ImplicitUsings>true</ImplicitUsings>".AsSpan(), StringComparison.Ordinal);
|
||||
|
||||
// Determine if WPF is used.
|
||||
useWpf = useWpf
|
||||
|| line.Contains("<UseWPF>true</UseWPF>".AsSpan(), StringComparison.Ordinal);
|
||||
|
||||
// Determine if Windows Forms is used.
|
||||
useWindowsForms = useWindowsForms
|
||||
|| line.Contains("<UseWindowsForms>true</UseWindowsForms>".AsSpan(), StringComparison.Ordinal);
|
||||
|
||||
// Find all custom implicit usings.
|
||||
foreach (var valueMatch in CustomImplicitUsingDeclarations().EnumerateMatches(line))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user