Click here to Skip to main content
12,404,017 members (62,755 online)
Click here to Skip to main content

Stats

84K views
1.9K downloads
142 bookmarked
Posted

.NET String Resources

, 19 Apr 2012 CPOL
Concepts and patterns for the handling of strings in multilingual applications.
docu
StringResources_en.pdf
Pub
Desktop.Release
de
Itenso.Community.StringResources.ResStrings.resources.dll
Itenso.Community.StringResources.SampleLibrary.resources.dll
Itenso.Community.StringResources.ResStrings.dll
Itenso.Community.StringResources.SampleLibrary.dll
Release
de
Itenso.Community.StringResources.ResStrings.resources.dll
Itenso.Community.StringResources.SampleLibrary.resources.dll
Itenso.Community.StringResources.ResStrings.dll
Itenso.Community.StringResources.SampleLibrary.dll
Silverlight.Release
de
Itenso.Community.StringResources.ResStrings.resources.dll
Itenso.Community.StringResources.SampleLibrary.resources.dll
Itenso.Community.StringResources.ResStrings.dll
Itenso.Community.StringResources.SampleLibrary.dll
Web.Release
de
Itenso.Community.StringResources.ResStrings.resources.dll
Itenso.Community.StringResources.SampleLibrary.resources.dll
Itenso.Community.StringResources.ResStrings.dll
Itenso.Community.StringResources.SampleLibrary.dll
WindowsPhone.Release
de
Itenso.Community.StringResources.ResStrings.resources.dll
Itenso.Community.StringResources.SampleLibrary.resources.dll
Itenso.Community.StringResources.ResStrings.dll
Itenso.Community.StringResources.SampleLibrary.dll
ResStrings
Properties
SampleApplication.Web
App_Data
App_GlobalResources
App_LocalResources
Global.asax
Properties
SampleApplication.WinForms
Properties
SampleApplication.Xaml
ApplicationIcon.png
Background.png
Properties
SplashScreenImage.jpg
SampleLibrary
Images
Status.Error.png
Status.Info.png
Status.Ok.png
Status.Warning.png
Properties
StringResources.suo
StringResources.Desktop.suo
StringResources.Silverlight.suo
StringResources.Web.suo
StringResources.WindowsPhone.suo
StringResources.WinForms.suo
// -- FILE ------------------------------------------------------------------
// name       : EnumItem.cs
// project    : Itenso String Resources
// created    : Jani Giannoudis - 2011.09.09
// language   : c#
// environment: .NET 4.0
// copyright  : (c) 2004-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;

namespace Itenso.Community.StringResources.ResStrings
{

	// ------------------------------------------------------------------------
	public sealed class EnumItem<T> where T : struct
	{

		// ----------------------------------------------------------------------
		internal EnumItem( T value, string description )
		{
			if ( string.IsNullOrEmpty( description ) )
			{
				throw new ArgumentNullException( "description" );
			}
			EnumTool.CheckEnumType( typeof( T ) );

			this.value = value;
			this.description = description;
		} // EnumItem

		// ----------------------------------------------------------------------
		public T Value
		{
			get { return value; }
		} // Value

		// ----------------------------------------------------------------------
		public string Description
		{
			get { return description; }
		} // Description

		// ----------------------------------------------------------------------
		/// <summary>
		/// Attention: special implementation!
		/// This method will accept other instances of this class which represent the
		/// same value but which may have different descriptions. It further accepts
		/// enum values which match the value this instance represents too!
		/// This is necessary for proper operation in cases where enums are mapped to
		/// some GUI component via automatic converters.
		/// </summary>
		/// <param name="obj">the object to compare against</param>
		/// <returns>true if the given object represent an instance of this class
		/// for the same value or for the enum value this instance stands for</returns>
		public override bool Equals( object obj )
		{
			if ( obj == this )
			{
				return true;
			}
			if ( obj == null )
			{
				return false;
			}
			Type objType = obj.GetType();
			if ( typeof( T ) == objType )
			{
				// special case: enum value comparison, see method docs for details
				return value.Equals( obj );
			}
			return typeof( EnumItem<T> ) == objType &&
				value.Equals( ( (EnumItem<T>)obj ).value );
		} // Equals

		// ----------------------------------------------------------------------
		public override int GetHashCode()
		{
			// we must return the same hash as the value we represent to conform to
			// the contract with Equals() ...
			return value.GetHashCode();
		} // GetHashCode

		// ----------------------------------------------------------------------
		public override string ToString()
		{
			return description;
		} // ToString

		// ----------------------------------------------------------------------
		// members
		private readonly T value;
		private readonly string description;

	} // class EnumItem

} // namespace Itenso.Community.StringResources.ResStrings
// -- EOF -------------------------------------------------------------------

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)

Share

About the Author

Jani Giannoudis
Software Developer (Senior)
Switzerland Switzerland
Jani is Co-founder of Meerazo.com, a free service which allows to share resources like locations, things, persons and their services in a cooperating group of people.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160721.1 | Last Updated 20 Apr 2012
Article Copyright 2011 by Jani Giannoudis
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid