//
//  SerializableBinaryDictionary.cs
//
//  Author:
//       Denis Oleynik <denis@meliorgames.com>
//
//  Copyright (c) 2013 Melior Games Inc.
//
//
// ------------------------------------------------------------------------------
//  <autogenerated>
//      This code was generated by a tool.
//      Mono Runtime Version: 4.0.30319.1
// 
//      Changes to this file may cause incorrect behavior and will be lost if 
//      the code is regenerated.
//  </autogenerated>
// ------------------------------------------------------------------------------
using System;
using System.Runtime.Serialization;
using System.Collections.Generic;


namespace DotOriko.Data.Serialization
{
	[Serializable]
	public sealed class SerializableBinaryDictionary<V>:Dictionary<string,V>,ISerializable
	{
		private const string KEYS = "___keys";

		#region ISerializable implementation

		public new void GetObjectData (SerializationInfo info, StreamingContext context)
		{
			List<string> keys = new List<string>();

			foreach(string key in this.Keys)
			{
				keys.Add(key);

				info.AddValue(key,this[key]);
			}

			info.AddValue(KEYS, keys.ToArray());
		}

		public SerializableBinaryDictionary(SerializationInfo info, StreamingContext context)
		{
			string[] keys = (string[])info.GetValue(KEYS,typeof(string[]));

			foreach(string key in keys)
			{
				this.Add(key,(V)info.GetValue(key,typeof(V)));
			}
		}

		#endregion

		public SerializableBinaryDictionary ()
		{
		}
	}
}

