public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token) { MatchResultType resultType = MatchResultType.NotApplicable; DetectedLineEndings lineEndings = DetectedLineEndings.NotApplicable; try { using (StreamReader reader = new StreamReader(file.FullName)) { lineEndings = TextUtil.GetLineEndings(reader, false, token); } if (lineEndings == m_Parameters.LineEndings) { resultType = MatchResultType.Yes; } else { resultType = MatchResultType.No; } } catch (Exception ex) { } return(new MatchResult(resultType, lineEndings.ToString())); }
public override string[] GetValues(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token) { DetectedLineEndings lineEndings = DetectedLineEndings.NotApplicable; string value = "N/A"; try { using (StreamReader reader = new StreamReader(file.FullName)) { lineEndings = TextUtil.GetLineEndings(reader, false, token); } value = lineEndings.ToString(); } catch (Exception ex) { } return(new string[] { value }); }
public static string GetNewline(FileInfo file, LineEndings lineEndings) { switch (lineEndings) { case LineEndings.MatchInput: if (file == null) { return(Environment.NewLine); } using (StreamReader reader = new StreamReader(file.OpenRead())) { DetectedLineEndings detected = GetLineEndings(reader, true, CancellationToken.None); switch (detected) { case DetectedLineEndings.Windows: return("\r\n"); case DetectedLineEndings.Unix: return("\n"); case DetectedLineEndings.ClassicMacOS: return("\r"); default: return(Environment.NewLine); } } case LineEndings.Windows: return("\r\n"); case LineEndings.Unix: return("\n"); case LineEndings.ClassicMacOS: return("\r"); default: return(Environment.NewLine); } }