avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ymikul...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/csframework/src/cs/Util RuntimeSerializer.cs
Date Thu, 23 Jan 2003 21:49:51 GMT
ymikulski    2003/01/23 13:49:51

  Added:       csframework/src/cs/Util RuntimeSerializer.cs
  Log:
  no message
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/csframework/src/cs/Util/RuntimeSerializer.cs
  
  Index: RuntimeSerializer.cs
  ===================================================================
  //------------------------------------------------------------------------------
  // Copyright (C) The Apache Software Foundation. All rights reserved.
  //
  // This software is published under the terms of the Apache Software License
  // version 1.1, a copy of which has been included  with this distribution in
  // the LICENSE.txt file.
  //------------------------------------------------------------------------------
  using System;
  using System.Collections;
  using System.Runtime.Serialization;
  
  namespace Apache.Avalon.Util
  {
  	/// <summary>
  	///	Utility class that makes it easier to serialize objects.
  	/// </summary>
  	internal class RuntimeSerializer
  	{
  		internal static void SerializeIDictionary(SerializationInfo info, IDictionary dictionary,

  			string nameKeys, string nameValues)
  		{
  			SerializeICollection(info, dictionary.Keys, nameKeys);
  			SerializeICollection(info, dictionary.Values, nameValues);
  		}
  
  		internal static IDictionary DeserializeIDictionary(SerializationInfo info, string nameKeys,
string nameValues)
  		{
  			Hashtable hashtable = new Hashtable();
  
  			object[] keys = DeserializeArray(info, nameKeys); 
  			object[] values = DeserializeArray(info, nameValues);
  
  			for (int i = 0; i < keys.Length; i++)
  			{
  				hashtable[keys[i]] = values[i];
  			}
  
  			return (IDictionary) hashtable;
  		}
  
  		internal static void SerializeICollection(SerializationInfo info, ICollection collection,
string name)
  		{
  			object[] elements = new object[collection.Count];
  			collection.CopyTo(elements, 0);
  
  			SerializeArray(info, elements, name);
  		}
  
  		internal static ICollection DeserializeICollection(SerializationInfo info, string name)
  		{
  			return (ICollection) DeserializeArray(info, name);
  		}
  
  		internal static void SerializeArray(SerializationInfo info, object[] array, string name)
  		{
  			info.AddValue(name, array, typeof(object[]));
  		}
  
  		internal static object[] DeserializeArray(SerializationInfo info, string name)
  		{
  			return (object[]) info.GetValue(name, typeof(object[]));
  		}
  	}
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message