Click here to Skip to main content
11,567,926 members (44,208 online)
Click here to Skip to main content
Add your own
alternative version

Enhanced String Handling II

, 16 Dec 2010 CPOL 15.8K 173 13
Overcoming limitations of: Enhanced String Handling
EnhancedStringEvaluate.zip
EnhancedStringEvaluate
bin
Debug
ConfigEvaluate.vshost.exe
ConfigEvaluate.vshost.exe.manifest
EnhancedStringEvaluate.dll
EnhancedStringEvaluate.pdb
ConcordPairEvaluate.csproj.vs10x
EnhancedStringEvaluate.csproj.user
EnhancedStringEvaluate.csproj.vs10x
obj
Debug
Decl
EnhancedStringEvaluate.dll
EnhancedStringEvaluate.pdb
DesignTimeResolveAssemblyReferencesInput.cache
EnhancedStringEvaluate.dll
EnhancedStringEvaluate.pdb
Refactor
ConfigEvaluate.dll
ResolveAssemblyReference.cache
TempPE
Properties
EvaluateTest
bin
Debug
EnhancedStringEvaluate.dll
EnhancedStringEvaluate.pdb
EvaluateSampleTest.dll
EvaluateSampleTest.pdb
EvaluateTest.dll
EvaluateTest.pdb
TestEvaluation.exe
TestEvaluation.pdb
EvaluateSampleTest.csproj.vs10x
EvaluateTest.csproj.vs10x
obj
Debug
Decl
EvaluateSampleTest.dll
EvaluateSampleTest.pdb
DesignTimeResolveAssemblyReferencesInput.cache
EvaluateSampleTest.dll
EvaluateSampleTest.pdb
EvaluateTest.dll
EvaluateTest.pdb
ResolveAssemblyReference.cache
TempPE
Properties
TestEvaluate
bin
Debug
abc.text
EnhancedStringEvaluate.dll
EnhancedStringEvaluate.pdb
TestEvaluate.exe
TestEvaluate.pdb
TestEvaluate.vshost.exe.manifest
TestEvaluation.exe
TestEvaluation.pdb
TestEvaluation.vshost.exe
TestEvaluation.vshost.exe.manifest
TestOnTheFlyConfig.vshost.exe
TestOnTheFlyConfig.vshost.exe.manifest
obj
Debug
Decl
TestEvaluation.exe
TestEvaluation.pdb
DesignTimeResolveAssemblyReferencesInput.cache
Refactor
ResolveAssemblyReference.cache
TempPE
TestEvaluate.exe
TestEvaluate.pdb
TestEvaluation.exe
TestEvaluation.pdb
ProcessEvaluate
Properties
TestEvaluate.csproj.vs10x
TestEvaluation.csproj.user
TestEvaluation.csproj.vs10x
TestOnTheFlyConfig.csproj.vs10x
Enhanced String Handling II.pdf
using System;
using System.Collections.Generic;


namespace EnhancedStringEvaluate
{
	/// We would like the identifier to be case insensitive, so we employ a 
	/// Dictionary<string, EnhancedStrPairElement> where the 1st generic parameter, 
	/// a string, is the identifier of the pair, operated on with the ToUpper() 
	/// function.  In this way we ensure that the search for the identifier is:
	///		>	case insensitive 
	///		>	we do not loose the original casing (it is still stored within 
	///			the EnhancedStrPairElement (2nd generic parameter)
	///		>	and this mechanism is fairly simple to implement and understand
	/// </summary>
	[Serializable]
	public sealed class EnhancedStrPairElement
	{
		public EnhancedStrPairElement(string identifier, string value)
		{
			Indetifier = identifier;
			Value = value;
		}

		/// <summary>
		/// Identifier--is immutable not only because string is immutable but 
		/// also because there is no way to change it outside the constructor.
		/// Now it is suited for a Dictionary<..> key, or a Hashtable(..) key.
		/// </summary>
		public string Indetifier { get; private set; }

		/// <summary>Value may change by the outside world</summary>
		public string Value { get; set; }

		public static explicit operator KeyValuePair<string, string>(EnhancedStrPairElement elem)
		{
			return new KeyValuePair<string, string>(elem.Indetifier, elem.Value);
		}

		public static implicit operator EnhancedStrPairElement(KeyValuePair<string, string> elem)
		{
			return new EnhancedStrPairElement(elem.Key, elem.Value);
		}

		public KeyValuePair<string, string> ToKeyValuePair() { return (KeyValuePair<string, string>)this; }

		public override string ToString()
		{
			return string.Format("({0}, {1})", Indetifier, Value);
		}

		private static EnhancedStrPairElement EmptyEnhancedStrElement = new EnhancedStrPairElement(null, null);
		public static EnhancedStrPairElement Empty { get { return EmptyEnhancedStrElement; } }
	}
}

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

Avi Farah
United States United States
avifarah@gmail.com

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 16 Dec 2010
Article Copyright 2010 by Avi Farah
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid