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 Beams = new Dictionary();
public readonly Dictionary Columns = new Dictionary();
public static Dictionary 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.