Last active
December 24, 2025 18:12
-
-
Save sunmeat/ec7c94b2b55bed40d43e05e464056319 to your computer and use it in GitHub Desktop.
DLL use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace UseDll | |
| { | |
| public class Person | |
| { | |
| public string? Name { get; set; } | |
| public int Age { get; set; } | |
| } | |
| internal class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var facade = new FileFacade(); | |
| var person = new Person { Name = "Alex", Age = 35 }; | |
| string textFilePath = "person.txt"; | |
| facade.WriteToFile(textFilePath, person.Name, "text"); // зберігаємо лише ім'я | |
| var personNameFromText = facade.ReadFromFile<string>(textFilePath, "text"); | |
| Console.WriteLine($"Text file: {personNameFromText}"); | |
| string csvFilePath = "person.csv"; | |
| facade.WriteToFile(csvFilePath, person, "csv"); | |
| var personFromCsv = facade.ReadFromFile<Person>(csvFilePath, "csv"); | |
| Console.WriteLine($"CSV file: {personFromCsv.Name}, {personFromCsv.Age}"); | |
| string xmlFilePath = "person.xml"; | |
| facade.WriteToFile(xmlFilePath, person, "xml"); | |
| var personFromXml = facade.ReadFromFile<Person>(xmlFilePath, "xml"); | |
| Console.WriteLine($"XML file: {personFromXml.Name}, {personFromXml.Age}"); | |
| string jsonFilePath = "person.json"; | |
| facade.WriteToFile(jsonFilePath, person, "json"); | |
| var personFromJson = facade.ReadFromFile<Person>(jsonFilePath, "json"); | |
| Console.WriteLine($"JSON file: {personFromJson.Name}, {personFromJson.Age}"); | |
| person.Age = 36; | |
| facade.UpdateFile(jsonFilePath, person, "json"); | |
| var updatedPersonFromJson = facade.ReadFromFile<Person>(jsonFilePath, "json"); | |
| Console.WriteLine($"Updated JSON file: {updatedPersonFromJson.Name}, {updatedPersonFromJson.Age}"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment