in Sharpmake.Generators/VisualStudio/Csproj.cs [2978:3078]
private CsProjSubTypesInfos DetermineWindowsFormsSubTypes(List<Project.Configuration> configurations, List<string> sourceFiles)
{
lock (s_allCachedCsProjSubTypesInfosLock)
{
if (s_allCachedCsProjSubTypesInfos == null)
{
var listTypes = Util.DeserializeAllCsprojSubTypesJson<List<CsProjSubTypesInfos>>();
s_allCachedCsProjSubTypesInfos = listTypes?.Where(p => p != null).ToList() ?? new List<CsProjSubTypesInfos>();
}
}
List<string> unresolvedSourceFiles = new List<string>();
Project.Configuration config = configurations.First();
string csProjFullPath = config.ProjectFullFileNameWithExtension;
string projectPath = config.ProjectPath;
if (!File.Exists(csProjFullPath))
{
return null;
}
CsProjSubTypesInfos cachedCsprojSubTypesInfos = s_allCachedCsProjSubTypesInfos.Find(p => p.CsProjFullPath == csProjFullPath);
DateTime csProjLastWriteTime = File.GetLastWriteTime(csProjFullPath);
if (cachedCsprojSubTypesInfos != null && cachedCsprojSubTypesInfos.LastWriteTime.Equals(csProjLastWriteTime))
{
return cachedCsprojSubTypesInfos;
}
CsProjSubTypesInfos csProjSubTypesInfos = new CsProjSubTypesInfos
{
CsProjFullPath = csProjFullPath,
LastWriteTime = csProjLastWriteTime,
SubTypeInfos = new List<CsProjSubTypesInfos.SubTypeInfo>()
};
foreach (string sourceFile in sourceFiles)
{
// Skip .designer.cs files as we know they are not Windows Form files.
if (sourceFile.EndsWith(".designer.cs", StringComparison.OrdinalIgnoreCase))
continue;
string sourceFilePath = Path.Combine(projectPath, sourceFile);
// Skip missing files
if (!File.Exists(sourceFilePath))
continue;
DateTime sourceFileLastWriteTime = File.GetLastWriteTime(sourceFilePath);
CsProjSubTypesInfos.SubTypeInfo matchingCachedSubTypeInfo = cachedCsprojSubTypesInfos ==
null ? new CsProjSubTypesInfos.SubTypeInfo() : cachedCsprojSubTypesInfos.SubTypeInfos.Find(s => string.Equals(s.FileName, sourceFile, StringComparison.OrdinalIgnoreCase));
if (matchingCachedSubTypeInfo != null && matchingCachedSubTypeInfo.LastWriteTime.Equals(sourceFileLastWriteTime))
{
csProjSubTypesInfos.SubTypeInfos.Add(matchingCachedSubTypeInfo);
continue;
}
string sourceFileData = File.ReadAllText(sourceFilePath);
Match match = s_winFormSubTypeRegex.Match(sourceFileData);
if (match.Success)
{
string subType = match.Groups[1].Value;
CsProjSubTypesInfos.SubTypeInfo subTypesInfo = new CsProjSubTypesInfos.SubTypeInfo
{
FileName = sourceFile,
LastWriteTime = sourceFileLastWriteTime,
SubType = subType
};
csProjSubTypesInfos.SubTypeInfos.Add(subTypesInfo);
}
else
{
unresolvedSourceFiles.Add(sourceFile);
}
}
if (unresolvedSourceFiles.Count > 0)
{
Dictionary<string, string> csprojSubTypes = ExtractSubTypesFromCsProjFile(csProjFullPath);
foreach (KeyValuePair<string, string> subType in csprojSubTypes)
{
string matchingSourceFile = unresolvedSourceFiles.Find(s => s == subType.Key);
if (string.IsNullOrEmpty(matchingSourceFile))
continue;
CsProjSubTypesInfos.SubTypeInfo subTypesInfo = new CsProjSubTypesInfos.SubTypeInfo
{
FileName = matchingSourceFile,
LastWriteTime = File.GetLastWriteTime(Path.Combine(projectPath, matchingSourceFile)),
SubType = subType.Value
};
csProjSubTypesInfos.SubTypeInfos.Add(subTypesInfo);
}
}
return csProjSubTypesInfos;
}