Created
May 28, 2018 22:01
-
-
Save mcclure/69aacde90c1f8b8e5a4fa096d0fccdef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.Serialization.Formatters.Binary; | |
using System.IO; | |
// NOTE A: Change the "struct" to a "class" on line NOTE A below and crash disappears | |
// NOTE B: Change the "float[] data" to "float data;" on line NOTE B below and crash disappears | |
// NOTE C: Change SamCombatant() to PlayerCombatant() on line NOTE C below and crash disappears | |
class Test { | |
[Serializable()] | |
public struct SerializableColor { // NOTE A | |
public float[] data; // NOTE B | |
public SerializableColor(float a) { | |
data = new float[] {a}; | |
} | |
} | |
[Serializable()] | |
public class PlayerCombatant { | |
SerializableColor color; | |
public PlayerCombatant() { | |
color = new SerializableColor(1); | |
} | |
} | |
[Serializable()] | |
public class SamCombatant : PlayerCombatant { | |
} | |
static void Main() { | |
Console.WriteLine("AWAKE"); | |
// Serialize to file | |
{ | |
FileStream fs = new FileStream("DataFile.dat", FileMode.Create); | |
BinaryFormatter formatter = new BinaryFormatter(); | |
formatter.Serialize(fs, new SamCombatant()); // NOTE C | |
fs.Close(); | |
} | |
// Deserialize from file | |
{ | |
FileStream fs = new FileStream("DataFile.dat", FileMode.Open); | |
BinaryFormatter formatter = new BinaryFormatter(); | |
formatter.Deserialize(fs); | |
fs.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment