示例#1
0
        static void Main(string[] args)
        {
            Biography     personBio = new Biography("Ivan", "Ivanov", 109787670, " +3752901234567", "DJ");
            BiographyFile bioFile   = new BiographyFile();

            Console.WriteLine(personBio.ToString());

            bioFile.CompressOrDecompressBio(personBio, Mode.Serialize);
        }
示例#2
0
        private void SerializeObject(Biography bio)
        {
            using (StreamWriter sw = new StreamWriter(pathToFile, false))
            {
                string jsonBiography = JsonSerializer.Serialize <Biography>(bio);

                sw.Write(jsonBiography);
                Console.WriteLine($"The object serialized to file {pathToFile}.\n");
            }
        }
示例#3
0
        private Biography DeserializeObject()
        {
            Biography bio = null;

            using (StreamReader sr = new StreamReader(pathToFile))
            {
                string jsonBiography = sr.ReadToEnd();
                bio = JsonSerializer.Deserialize <Biography>(jsonBiography);
                Console.WriteLine($"The object deserialized from the file {pathToFile}.\n");
            }

            return(bio);
        }
示例#4
0
        public void CompressOrDecompressBio(Biography bio, Mode mode)
        {
            switch (mode)
            {
            case Mode.Serialize:
            {
                SerializeObject(bio);
                break;
            }

            case Mode.Deserialize:
            {
                Biography = DeserializeObject();
                break;
            }

            default:
            {
                Console.WriteLine("Error\n");
                break;
            }
            }
        }
示例#5
0
        public void GetBiography(Biography bio)
        {
            string biography = bio == null ? "Error. Bio is null" : $"{bio.ToString()}";

            Console.WriteLine(biography);
        }