in src/Microsoft.VisualStudio.SlowCheetah.VS/Package/PreviewTransformCommand.cs [282:346]
private bool TryGetFileToTransform(IVsHierarchy hierarchy, uint parentId, string transformName, out uint docId, out string documentPath)
{
IVsProject project = (IVsProject)hierarchy;
// Get the project configurations to use in comparing the name
IEnumerable<string> configs = ProjectUtilities.GetProjectConfigurations(hierarchy);
docId = 0;
if (ErrorHandler.Failed(project.GetMkDocument(parentId, out documentPath)))
{
return false;
}
if (!PackageUtilities.IsPathValid(documentPath))
{
return false;
}
// Start by checking if the parent is the source file
// Here, we can do a generic transform file test to allow for transformations that aren't associated with build configurations
if (PackageUtilities.IsGenericFileTransform(Path.GetFileName(documentPath), transformName))
{
docId = parentId;
return true;
}
else
{
// If the parent is no the file to transform, look at all of the original file's siblings
// Starting with the parent's first visible child
hierarchy.GetProperty(parentId, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out object childIdObj);
docId = (uint)(int)childIdObj;
if (ErrorHandler.Failed(project.GetMkDocument(docId, out documentPath)))
{
docId = 0;
documentPath = null;
return false;
}
if (PackageUtilities.IsPathValid(documentPath)
&& PackageUtilities.IsFileTransformForBuildConfiguration(Path.GetFileName(documentPath), transformName, configs))
{
return true;
}
else
{
// Continue on to the the next visible siblings until there are no more files to analyze
while (docId != VSConstants.VSITEMID_NIL)
{
hierarchy.GetProperty(docId, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out childIdObj);
docId = (uint)(int)childIdObj;
if (ErrorHandler.Succeeded(project.GetMkDocument(docId, out documentPath))
&& PackageUtilities.IsPathValid(documentPath)
&& PackageUtilities.IsFileTransformForBuildConfiguration(Path.GetFileName(documentPath), transformName, configs))
{
return true;
}
}
}
}
// If we run out of files, the source file has not been found
docId = 0;
documentPath = null;
return false;
}