Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / C#

Zeta .NET Base Libraries

Rate me:
Please Sign up or sign in to vote.
4.41/5 (44 votes)
30 Mar 2007CPOL3 min read 152K   2.4K   147  
A small set of general-purpose classes for using in .NET applications
namespace ZetaLib.Core.Common
{
	#region Using directives.
	// ------------------------------------------------------------------

	using System;
	using System.Collections;
	using System.Data;
	using System.IO;
	using System.Runtime.Serialization;
	using System.Runtime.Serialization.Formatters;
	using System.Runtime.Serialization.Formatters.Binary;
	using System.Text;
	using System.Xml;
	using Microsoft.Win32;
	using ZetaLib.Core.Properties;
	using ZetaLib.Core.Logging;

	// ------------------------------------------------------------------
	#endregion

	/////////////////////////////////////////////////////////////////////////

	/// <summary>
	/// Base class which provide some more methods to the 
	/// IPersistentPairStorage interface.
	/// </summary>
	public abstract class PersistentPairStorageBase :
		IPersistentPairStorage
	{
		#region Public methods.
		// ------------------------------------------------------------------

		/// <summary>
		/// Serialize a value and persist it.
		/// The opposite to "DeserializeValue".
		/// </summary>
		/// <param name="name">The name.</param>
		/// <param name="val">The val.</param>
		public void SerializeValue(
			string name,
			object val )
		{
			if ( val == null )
			{
				PersistValue( name, null );
			}
			else
			{
				PersistValue( name, StringHelper.SerializeToString( val ) );
			}
		}

		/// <summary>
		/// Deserializes a value from persistent storage.
		/// The opposite to "SerializeValue".
		/// </summary>
		/// <param name="name">The name.</param>
		/// <returns>Returns NULL if not found.</returns>
		public object DeserializeValue(
			string name )
		{
			object o = RetrieveValue( name );

			if ( o == null || !(o is string) )
			{
				return null;
			}
			else
			{
				return StringHelper.DeserializeFromString( o.ToString() );
			}
		}

		// ------------------------------------------------------------------
		#endregion

		#region IPersistentPairStorage members.
		// ------------------------------------------------------------------

		/// <summary>
		/// Persist a value.
		/// </summary>
		/// <param name="name">The name of the value to persist.</param>
		/// <param name="value">The value to persist.</param>
		public abstract void PersistValue(
			string name,
			object value );

		/// <summary>
		/// Retrieve a value.
		/// </summary>
		/// <param name="name">The name of the value to retrieve.</param>
		/// <returns>
		/// Returns the retrieved value or NULL if not available.
		/// </returns>
		public abstract object RetrieveValue(
			string name );

		/// <summary>
		/// Retrieve a value.
		/// </summary>
		/// <param name="name">The name of the value to retrieve.</param>
		/// <param name="fallbackValue">The value to return when the retrieved
		/// value is not available.</param>
		/// <returns>
		/// Returns the retrieved value or 'fallbackValue' if not available.
		/// </returns>
		public abstract object RetrieveValue(
			string name,
			object fallbackValue );

		// ------------------------------------------------------------------
		#endregion
	}

	/////////////////////////////////////////////////////////////////////////
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions