+ 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
1 Odpowiedź
+ 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