#include "stdafx.h"
#include "refCSerializableDictionary.h"

namespace FDK
{
	generic<typename TKey, typename TValue>
	XmlSchema^ CSerializableDictionary<TKey, TValue>::GetSchema()
	{
		this->Disposed->tDispose済みまたは実行中なら例外発生( "CSerializableDictionary" );
		return nullptr;
	}

	generic<typename TKey, typename TValue>
	void CSerializableDictionary<TKey, TValue>::ReadXml( XmlReader^ reader )
	{
		this->Disposed->tDispose済みまたは実行中なら例外発生( "CSerializableDictionary" );

		XmlSerializer^ s = gcnew XmlSerializer( KeyValue::typeid );

		reader->Read();
		while( XmlNodeType::EndElement != reader->NodeType )
		{
			KeyValue^ kv = (KeyValue^) s->Deserialize( reader );
			Add( kv->Key, kv->Value );
		}
		reader->Read();
	}

	generic<typename TKey, typename TValue>
	void CSerializableDictionary<TKey, TValue>::WriteXml( XmlWriter^ writer )
	{
		this->Disposed->tDispose済みまたは実行中なら例外発生( "CSerializableDictionary" );

		XmlSerializer^ s = gcnew XmlSerializer( KeyValue::typeid );

		for each ( TKey key in Keys )
		{
			s->Serialize( writer, gcnew KeyValue( key, this[ key ] ) );
		}
	}
}