protected bool TryInfluenceAttributeAnnotation(string s, out string result, AttributeAnnotationCallback callback) { result = null; // The proper response here is a bit nuanced. var x = callback(s).Trim(); // If we were working with files, great thing is `removing´ it from the project is tantamount to simply deleting it. return(x.Any() && (result = x) != s); }
protected bool TryInfluenceAttributeAnnotation(string fileName, AttributeAnnotationCallback callback) { var filePath = Path.Combine(ProjectName, fileName); string s; using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var reader = new StreamReader(fs)) { s = reader.ReadToEnd(); } } // The proper response here is a bit nuanced. var x = callback(s).Trim(); if (x == null) { return false; } if (!x.Any()) { // The great thing is `removing´ a file from the project is tantamount to simply deleting it. File.Delete(filePath); return true; } // Yes, `Create´ here... Because we may want to Truncate the result. using (var fs = File.Open(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) { using (var writer = new StreamWriter(fs)) { writer.Write(x); } } return s != x; }