+ 2

Deserialize File Variables In A Custom Extension File? (C#)

I Need To storage variables In a File with Custom Extension And Open That variables In my app

23rd Apr 2018, 3:11 AM
SebGM2018
SebGM2018 - avatar
1 Réponse
+ 1
Add a [Serializable] attribute to the class being serialized. [Serializeable] public class NiceClass { } Make a Serialize method and a Deserialize method public void SerializeObject<T>(string filename, T obj) { Stream stream = File.Open(filename, FileMode.Create); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(stream, obj); stream.Close(); } public T DeSerializeObject<T>(string filename) { T objectToBeSerialized; Stream stream = File.Open(filename, FileMode.Open); BinaryFormatter binaryFormatter = new BinaryFormatter(); objectToBeSerialized = (T)binaryFormatter.Deserialize(stream); return objectToBeSerialized; } I use a binaryFormatter but you can also use a XmlFormatter
23rd Apr 2018, 10:18 PM
sneeze
sneeze - avatar