using System.Web.Script.Serialization;
// JSON serialize
JavaScriptSerializer serializer = new JavaScriptSerializer(new FigureTypeResolver());
var json = serializer.Serialize(figureList.ToArray());
Console.WriteLine(json);
// JSON deserialize
JavaScriptSerializer deserializer = new JavaScriptSerializer(new FigureTypeResolver());
var loadedFigureList = (List<Figure>)deserializer.Deserialize(json, figureList.GetType());
// convert every item to Figure
for (int i = 0; i < loadedFigureList.Count; i++)
{
var f = (Figure)loadedFigureList[i];
FigureType type = FigureCalculator.GetFigureType(f);
Console.WriteLine(type);
Console.WriteLine(FigureCalculator.Perimeter(type, f));
Console.WriteLine(FigureCalculator.Area(type, f));
}