I have two classes as below and I\'m using them in two separate Dictionaries. How can I Serialize these two Dictionaries to a single file? my Serializa
Create a class marked with the Serializable attribute, containing instances of these two dictionaries:
[Serializable]
public class Building
{
public static Building Instance = new Building();
public readonly Dictionary<string, Beam> Beams = new Dictionary<string, Beam>();
public readonly Dictionary<string, Column> Columns = new Dictionary<string, Column>();
public static Dictionary<string, Beam> AllBeams
{
get { return Instance.Beams; }
}
}
EDIT
A Singleton pattern used to avoid the exception.
In the other parts of the code use Building.Instance to access the dictionaries.
EDIT2
A static property introduced: Building.AllBeams. You can use it as shorthand.