Note that there are some explanatory texts on larger screens.

plurals
  1. POSerialization of ISolution - Roslyn CTP3
    primarykey
    data
    text
    <p>I have been experimenting with Roslyn in the context of meta-programming, but have encountered difficulties in persisting ISolution or IProject objects to a database. Here is what I have tried to serialize ISolution objects to a byte array and then back to an object. I ran into the class is not marked as serializable exception. I'm open to any ideas on this, if I am approaching this in the wrong way please feel free to say so.</p> <p>Update: My reason to need to serialize these items to a database involves experiments with genetic programming. Basically you can alter a solution, or project slightly then test that newly altered program and then use that altered program for future generations if it did well in the testing phase. Unfortunately, it is a little impractical to keep all these objects in memory all the time. A power outage is one good reason to persist the state of these entities, there are others as well. So I don't necessarily need to serialize these things to bytes per se, I could just save the minimum amount of information to allow me to reconstruct these objects when needed. However, I'm not sure of the most efficient way to achieve my end goal. </p> <pre><code>public static object ByteArrayToObject(this byte[] arrBytes) { MemoryStream serializationStream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); serializationStream.Write(arrBytes, 0, arrBytes.Length); serializationStream.Seek(0L, SeekOrigin.Begin); return formatter.Deserialize(serializationStream); } public static byte[] ObjectToByteArray(this object obj) { if (obj == null) { return null; } BinaryFormatter formatter = new BinaryFormatter(); MemoryStream serializationStream = new MemoryStream(); formatter.Serialize(serializationStream, obj); return serializationStream.ToArray(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload