Reputation: 5243
I have a custom list which I want to embed as a resource so it can be copied out with each new install. However, my list is serialized as a binary file and when I add it as a resource I can't just copy it out because C# treats it as a byte array. I need to be able to convert this byte array back to my custom list when I extract the file from my resources. Can someone give me an idea of how to accomplish this conversion?
Thanks!
Upvotes: 2
Views: 5121
Reputation: 178770
You need to deserialize the byte array back into an instance of your list. The way to do this depends on the mechanism by which you serialized it. If you used a BinaryFormatter
to serialize it, for example, use the same to deserialize.
Upvotes: 1
Reputation: 1063824
In what way have you serialized it? Normally you would just reverse that process. For example:
BinaryFormatter bf = new BinaryFormatter();
using(Stream ms = new MemoryStream(bytes)) {
List<Foo> myList = (List<Foo>)bf.Deserialize(ms);
}
Obviously you may need to tweak this if you have used a different serializer! Or if you can get the data as a Stream
(rather than a byte[]
) you can lose the MemoryStream
step...
Upvotes: 6
Reputation: 77580
How is the list being serialized? You should have access to an equivalent Deserialize()
method whose result you can cast back to the original list type.
Upvotes: 1