public static void Serialize <T>(string jsonFilePath, T obj, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(jsonFilePath, overwrite)) { JsonStreamSerializer.Serialize(fileStream, obj); } }
public async Task SerializeAsync(string projectFilePath, ProjectFile value, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(projectFilePath, overwrite)) { await this.VisualStudioProjectFileStreamSerializer.SerializeAsync(fileStream, projectFilePath, value); } }
public static void Serialize <T>(string binaryFilePath, T value, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(binaryFilePath, overwrite)) { BinaryStreamSerializer.Serialize(fileStream, value); } }
public void Serialize(string filePath, T value, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(filePath, overwrite)) { this.StreamSerializer.Serialize(fileStream, value); } }
public static void Serialize(string projectFilePath, ProjectFileModel projectFile, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(projectFilePath, overwrite)) { projectFile.XmlDocument.Save(fileStream); } }
private async Task DeserializeExampleProjectFile() { var exampleVisualStudioProjectFilePath01 = this.TestingDataDirectoryContentPathsProvider.GetExampleVisualStudioProjectFilePath01(); var projectFile = await this.VisualStudioProjectFileSerializer.DeserializeAsync(exampleVisualStudioProjectFilePath01); var testingDataDirectoryPathProvider = this.ServiceProvider.GetRequiredService <ITestingDataDirectoryPathProvider>(); var testingDataDirectoryPath = testingDataDirectoryPathProvider.GetTestingDataDirectoryPath(); var stringlyTypedPathOperator = this.ServiceProvider.GetRequiredService <IStringlyTypedPathOperator>(); // Pretend to serialize to a file in the testing data directory to get the project reference relative file paths to be correct. var tempOutputFilePath01 = stringlyTypedPathOperator.GetFilePath(testingDataDirectoryPath, "ProjectFile01.csproj"); var visualStudioProjectFileStreamSerializer = this.ServiceProvider.GetRequiredService <IVisualStudioProjectFileStreamSerializer>(); using (var memoryStream = new MemoryStream()) { await visualStudioProjectFileStreamSerializer.SerializeAsync(memoryStream, tempOutputFilePath01, projectFile); // Now actually serialize to the output file. var outputFilePath01 = this.TemporaryDirectoryFilePathProvider.GetTemporaryDirectoryFilePath("ProjectFile01.csproj"); using (var fileStream = FileStreamHelper.NewWrite(outputFilePath01)) { fileStream.Write(memoryStream.ToArray()); } } }
public static void Serialize(string projectFilePath, ProjectFileModel projectFile, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(projectFilePath, overwrite)) using (var xmlWriter = XmlWriterHelper.New(fileStream)) { projectFile.ProjectElement.Value.Save(xmlWriter); } }
public static void Serialize(string solutionFilePath, SolutionFile obj, bool overwrite = true) { using (var fileStream = FileStreamHelper.NewWrite(solutionFilePath, overwrite)) using (var textWriter = StreamWriterHelper.NewLeaveOpenAddBOM(fileStream)) { var solutionFileTextSerialializer = new SolutionFileTextSerializer(); solutionFileTextSerialializer.Serialize(textWriter, obj); } }
private static void EnsureBOMProduced() { var tempFilePath = @"C:\Temp\temp.txt"; using (var fileStream = FileStreamHelper.NewWrite(tempFilePath)) using (var writer = StreamWriterHelper.NewLeaveOpenAddBOM(fileStream)) { writer.WriteLine("Hello world! (BOM?)"); } }
public async Task SerializeAsync(string actualfilePath, string asFilePath, XDocumentVisualStudioProjectFile xElementVisualStudioProjectFile, bool overwrite = true) { // Modify. var modifiedXElementVisualStudioProjectFile = await this.FunctionalVisualStudioProjectFileSerializationModifier.ModifySerializationAsync(xElementVisualStudioProjectFile, asFilePath, this.MessageSink); // Prettify. await this.VisualStudioProjectFileXDocumentPrettifier.Prettify(modifiedXElementVisualStudioProjectFile.VisualStudoProjectFileXDocument); // Serialize. using (var fileStream = FileStreamHelper.NewWrite(actualfilePath, overwrite)) { await this.RelativePathsXDocumentVisualStudioProjectFileStreamSerializer.SerializeAsync(fileStream, modifiedXElementVisualStudioProjectFile, this.MessageSink); } }
private async Task CompareRoundTripBasicXmlSerializedFiles() { var inputProjectFilePath = this.TestingDataDirectoryContentPathsProvider.GetExampleVisualStudioProjectFilePath01(); var outputProjectFilePath = this.TemporaryDirectoryFilePathProvider.GetTemporaryDirectoryFilePath("ProjectFile01.csproj"); //var xElement = XElement.Load(inputProjectFilePath); // Does not preserve insignifcant whitespace. var xElement = XElement.Load(inputProjectFilePath, LoadOptions.PreserveWhitespace); // Because insignification whitespace is preserved, project file is identical when round-tripped. //xElement.Save(outputProjectFilePath); // Adds an XML document declaration, so no good a a project file serializer. using (var fileStream = FileStreamHelper.NewWrite(outputProjectFilePath)) using (var xmlWriter = XmlWriterHelper.New(fileStream)) { xElement.Save(xmlWriter); } await this.CompareFiles(inputProjectFilePath, outputProjectFilePath, "Files not equal."); }
private async Task CompareRoundTripRelativeFilePathsSerializedFiles() { var inputProjectFilePath = this.TestingDataDirectoryContentPathsProvider.GetExampleVisualStudioProjectFilePath01(); var outputProjectFilePath = this.TemporaryDirectoryFilePathProvider.GetTemporaryDirectoryFilePath("ProjectFile01.csproj"); var relativeFilePathsVisualStudioProjectFileStreamSerializer = this.ServiceProvider.GetRequiredService <IRelativePathsXDocumentVisualStudioProjectFileStreamSerializer>(); using (var inputFileStream = FileStreamHelper.NewRead(inputProjectFilePath)) { var visualStudioProjectFile = await relativeFilePathsVisualStudioProjectFileStreamSerializer.DeserializeAsync(inputFileStream, this.MessageSink); using (var outputFileStream = FileStreamHelper.NewWrite(outputProjectFilePath)) { await relativeFilePathsVisualStudioProjectFileStreamSerializer.SerializeAsync(outputFileStream, visualStudioProjectFile, this.MessageSink); } } await this.CompareFiles(inputProjectFilePath, outputProjectFilePath, "Files not equal."); }