private string CreateCommentBody(IRenderingContext targetContext, bool skipLineNumber, string extraText, bool useEndTagPosition, IRenderingContext replacementContext) { IZptElement targetElement = targetContext.Element, sourceElement = replacementContext?.Element ?? targetContext.Element; string fullFilename = targetContext.Element.SourceFile.FullName, filename, filePosition = useEndTagPosition? sourceElement.GetEndTagFileLocation() : sourceElement.GetFileLocation(), previousElement; if(!String.IsNullOrEmpty(targetContext.SourceAnnotationRootPath) && Directory.Exists(targetContext.SourceAnnotationRootPath) && File.Exists(fullFilename)) { var root = new DirectoryInfo(targetContext.SourceAnnotationRootPath); var file = new FileInfo(fullFilename); filename = file.IsChildOf(root)? file.GetRelativePath(root).Substring(1) : fullFilename; } else { filename = fullFilename; } filename = filename.Replace(Path.DirectorySeparatorChar.ToString(), "/"); if((!targetElement.IsRoot && targetElement.HasParent) || targetElement.CanWriteCommentWithoutParent) { previousElement = String.Empty; } else { previousElement = PREVIOUS_ELEMENT; } var body = (skipLineNumber || String.IsNullOrEmpty(filePosition))? filename : String.Format(POSITION_FORMAT, filename, filePosition); var extra = _renderExtraText? extraText?? String.Empty : String.Empty; return String.Concat(previousElement, extra, body); }
public void TestIsChildOf() { FileInfo file = new FileInfo(@"C:\SomeDirectory\SomeFile.txt"); Assert.IsTrue(file.IsChildOf(new DirectoryInfo(@"C:\SomeDirectory")), "Is child of C:\\SomeDirectory"); Assert.IsFalse(file.IsChildOf(new DirectoryInfo(@"C:\OtherDirectory")), "Is not child of C:\\OtherDirectory"); }