<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:snippet="http://codexchange.org/schemas/snippet/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title>CodeXchange: User Contributed Snippets</title>
    <link>http://www.codexchange.org</link>
    <description>Summary of the snippets published by a codexchange user</description>
    <language>en-us</language>
    <copyright>Copyright © CodeXchange, 2004-2006</copyright>
    <generator>CodeXchange RSS Feed Generator v1.0</generator>
    <webMaster>webmaster@codexchange.org</webMaster>
    <lastBuildDate>Thu, 15 Oct 2026 10:13:52 GMT</lastBuildDate>
    <ttl>20</ttl>
    <dc:language>en-us</dc:language>
    <dc:rights>Copyright © CodeXchange, 2004-2006</dc:rights>
    <dc:date>10/15/2026 10:13:52 AM</dc:date>
    <dc:publisher />
    <dc:creator>CodeXchange RSS Feed Generator v1.0</dc:creator>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=936bbfdc-a055-4eac-b98c-224acb204b53</guid>
      <title>C# : Return Information from the Call Stack to help in Debugging your Code</title>
      <link>/PreviewSnippet.aspx?SnippetID=936bbfdc-a055-4eac-b98c-224acb204b53</link>
      <description>C# : Return Information from the Call Stack to help in Debugging your Code [C#]</description>
      <author>Damon Carr</author>
      <pubDate>Mon, 02 May 2005 18:08:52 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=936bbfdc-a055-4eac-b98c-224acb204b53#comments</comments>
      <category>0f7510dd-92d6-4892-9539-4866adb651a3</category>
      <dc:title>C# : Return Information from the Call Stack to help in Debugging your Code</dc:title>
      <dc:date>5/2/2005 6:08:52 PM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>		public string CallingMethod
		{
			get
			{
				StackFrame sf;
				StackTrace st = new StackTrace(true);
				StringBuilder oString = new StringBuilder();
				for(int i =1; i< st.FrameCount; i++ )
				{
					// Note that high up the call stack, there is only
					// one stack frame.
					sf = st.GetFrame(i);
					oString.Append("METHOD: " + sf.GetMethod());
					oString.Append(" Line Number: " + sf.GetFileLineNumber() + AppUtils.StringSeperator);
					
				}
				return oString.ToString();
			}
		}</pre>]]></content:encoded>
      <snippet:downloads>3</snippet:downloads>
      <snippet:rating>3</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=6e2c97f7-cf2e-4e00-8acc-49f9a03780f7</guid>
      <title>C#: Code to Detect if a System is Shutting Down and will Exit with the Exit Code You Provide</title>
      <link>/PreviewSnippet.aspx?SnippetID=6e2c97f7-cf2e-4e00-8acc-49f9a03780f7</link>
      <description>C#: Code to Detect if a System is Shutting Down and will Exit with the Exit Code You Provide [J#]</description>
      <author>Damon Carr</author>
      <pubDate>Sun, 24 Apr 2005 02:21:46 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=6e2c97f7-cf2e-4e00-8acc-49f9a03780f7#comments</comments>
      <category>8c2f06f8-1c90-43ba-b7f6-72416ef60c2b</category>
      <dc:title>C#: Code to Detect if a System is Shutting Down and will Exit with the Exit Code You Provide</dc:title>
      <dc:date>4/24/2005 2:21:46 AM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>
			int exitcode = 0;
			const int END_CODE_SHUTTINGDOWN = 1024;
			try
			{
				String[] args = Environment.GetCommandLineArgs();
				// The first parameter on the command line would be the exit code you wanted the
				// process to return to the system
				if (args.Length > 1)
					exitcode = int.Parse(args[1]);
				else
					exitcode = END_CODE_SHUTTINGDOWN;
			}
			catch (Exception ex)
			{
				exitcode = ex.GetHashCode();
			}
			if (Environment.HasShutdownStarted)
				Environment.Exit(exitcode);
</pre>]]></content:encoded>
      <snippet:downloads>9</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>J#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=76d00e81-370a-4dbb-a25f-815a51128678</guid>
      <title>C#: Test for Out Of Memory using Unsafe Code</title>
      <link>/PreviewSnippet.aspx?SnippetID=76d00e81-370a-4dbb-a25f-815a51128678</link>
      <description>C#: Test for Out Of Memory using Unsafe Code [C#]</description>
      <author>Damon Carr</author>
      <pubDate>Mon, 02 May 2005 18:53:34 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=76d00e81-370a-4dbb-a25f-815a51128678#comments</comments>
      <category>0f7510dd-92d6-4892-9539-4866adb651a3</category>
      <dc:title>C#: Test for Out Of Memory using Unsafe Code</dc:title>
      <dc:date>5/2/2005 6:53:34 PM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>using System;
using System.Runtime.InteropServices;
public unsafe class Memory
{
	// Heap API flags
	const int HEAP_ZERO_MEMORY = 0x00000008;
	static int ph = GetProcessHeap();
    
	public static void* Alloc(int size) 
	{
		void* result = HeapAlloc(ph, HEAP_ZERO_MEMORY, size);
		if (result == null) 
			throw new OutOfMemoryException();
		return result;
	}
}
</pre>]]></content:encoded>
      <snippet:downloads>5</snippet:downloads>
      <snippet:rating>5</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=d4bafec2-3c86-48b6-8c7c-83d76fb4d65c</guid>
      <title>C#: Function to Find any Type by name by searching through all the refernced assemblied in your application and returning a .NET Type from the passed in (namespace qualified) string</title>
      <link>/PreviewSnippet.aspx?SnippetID=d4bafec2-3c86-48b6-8c7c-83d76fb4d65c</link>
      <description>C#: Function to Find any Type by name by searching through all the refernced assemblied in your application and returning a .NET Type from the passed in (namespace qualified) string [C#]</description>
      <author>Damon Carr</author>
      <pubDate>Sun, 24 Apr 2005 04:15:32 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=d4bafec2-3c86-48b6-8c7c-83d76fb4d65c#comments</comments>
      <category>0f7510dd-92d6-4892-9539-4866adb651a3</category>
      <dc:title>C#: Function to Find any Type by name by searching through all the refernced assemblied in your application and returning a .NET Type from the passed in (namespace qualified) string</dc:title>
      <dc:date>4/24/2005 4:15:32 AM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>		public Type FindTypeTypeFromStringName(String TypeName)
		{	
			/*************************************************************
			 * Damon W. Carr, CEO agilfactor
			 * 
			 * This code will find a Give Type using its String Name 
			 * across ALL ASSEMBLIES you have referenced and return the 
			 * Type of the item which is far more useful then just the 
			 * String name. If you only have one assembly you will not need
			 * this.
			 * 
			 * Discussion (?)
			 *			
			 *			Add an overload to allow the searching for both types
			 *			AND the assembly they are in when you know the type
			 *			you want AND the assembly and there are two types with		
			 *			the same name. 
			 * 
			 *			However if you know that much, you
			 *			really wouldn't need this function as you would just 
			 *			check the types in THAT assembly using reflection 
			 *			directly . You would not need this routine if you 
			 *			knew the Type's name and the assembly in other words.
			 * 
			 * CAVEATS:	Be aware, if you are looking for a Type and there
			 *			are more then one match, only the first one will be 
			 *			returned.
			 * ***********************************************************/
            		
			Assembly oEntryAssembly = Assembly.GetCallingAssembly();
			Type oMatchedType = null;
			AssemblyName[] ReferencedAssemblies = oEntryAssembly.GetReferencedAssemblies();
			Assembly oCurrentAssembly;
                        
			oMatchedType = oEntryAssembly.GetType(TypeName);
			if (oMatchedType == null) 
			{
				foreach(AssemblyName oName in ReferencedAssemblies)
				{
					/***********************************************************
					 * Assemblies are cached. This is not slow so don't worry
					 * about performance. This will perform very well
					 * *******************************************************/
					oCurrentAssembly = Assembly.Load(oName); //Load the assembly from the AssemblyName type
					oMatchedType = oCurrentAssembly.GetType(TypeName);
					if (oMatchedType != null)
					{
						//You Found the Type you Wanted
						break;
					}
					
				}
			}
			return oMatchedType;
       }</pre>]]></content:encoded>
      <snippet:downloads>3</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=d444b91f-490b-4326-947d-a9ce3d26f311</guid>
      <title>C# : Checks a String for null or Empty and returns a bool. This is a static so you invoke it from the class. There are no threading issues as String are immutable and the nature of the Thread Call Stack</title>
      <link>/PreviewSnippet.aspx?SnippetID=d444b91f-490b-4326-947d-a9ce3d26f311</link>
      <description>C# : Checks a String for null or Empty and returns a bool. This is a static so you invoke it from the class. There are no threading issues as String are immutable and the nature of the Thread Call Stack [C#]</description>
      <author>Damon Carr</author>
      <pubDate>Sun, 24 Apr 2005 15:50:45 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=d444b91f-490b-4326-947d-a9ce3d26f311#comments</comments>
      <category>de2012da-757e-4af6-8537-6799adb7bce1</category>
      <dc:title>C# : Checks a String for null or Empty and returns a bool. This is a static so you invoke it from the class. There are no threading issues as String are immutable and the nature of the Thread Call Stack</dc:title>
      <dc:date>4/24/2005 3:50:45 PM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>		public static bool StringEmpty(String StringToCheck)
		{
				
			if (StringToCheck == null || StringToCheck == String.Empty)
				return true;
			else
				return false;
		}</pre>]]></content:encoded>
      <snippet:downloads>12</snippet:downloads>
      <snippet:rating>2</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=7639d725-c70f-4fed-bac3-bd5452402a59</guid>
      <title>C# : Great Debug Information using the StackFrame</title>
      <link>/PreviewSnippet.aspx?SnippetID=7639d725-c70f-4fed-bac3-bd5452402a59</link>
      <description>C# : Great Debug Information using the StackFrame [C#]</description>
      <author>Damon Carr</author>
      <pubDate>Wed, 04 May 2005 16:26:55 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=7639d725-c70f-4fed-bac3-bd5452402a59#comments</comments>
      <category>0f7510dd-92d6-4892-9539-4866adb651a3</category>
      <dc:title>C# : Great Debug Information using the StackFrame</dc:title>
      <dc:date>5/4/2005 4:26:55 PM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>		public string CallingMethod
		{
			get
			{
				StackFrame sf;
				StackTrace st = new StackTrace(true);
				StringBuilder oString = new StringBuilder();
				for (int i = 1 ; i < st.FrameCount ; i++)
				{
					// Note that high up the call stack, there is only
					// one stack frame.
					sf = st.GetFrame(i);
					oString.Append("METHOD: " + sf.GetMethod());
					oString.Append(" Line Number: " + sf.GetFileLineNumber() + AppUtils.StringSeperator);
				}
				return oString.ToString();
			}
		}</pre>]]></content:encoded>
      <snippet:downloads>6</snippet:downloads>
      <snippet:rating>3</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=92a692ef-f7f2-498d-94b8-d1ef59a601f8</guid>
      <title>C# : A Best Practice Use of the ReaderWriterLock for Multithreaded Environments</title>
      <link>/PreviewSnippet.aspx?SnippetID=92a692ef-f7f2-498d-94b8-d1ef59a601f8</link>
      <description>C# : A Best Practice Use of the ReaderWriterLock for Multithreaded Environments [C#]</description>
      <author>Damon Carr</author>
      <pubDate>Thu, 28 Apr 2005 15:02:52 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=92a692ef-f7f2-498d-94b8-d1ef59a601f8#comments</comments>
      <category>0f7510dd-92d6-4892-9539-4866adb651a3</category>
      <dc:title>C# : A Best Practice Use of the ReaderWriterLock for Multithreaded Environments</dc:title>
      <dc:date>4/28/2005 3:02:52 PM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>	public static String GetApplicationName()
		{	
			// This is mostly here as a tutorial on using the Reader Writer Lock;
			const int CONST_WAIT_TIME_TO_AQUIRE = 1000;
            
			ReaderWriterLock oRWLock;
			
			if (AppUtils.StringEmpty(AppName)) {
				oRWLock = new ReaderWriterLock();
                
				try {
					oRWLock.AcquireReaderLock(CONST_WAIT_TIME_TO_AQUIRE);
				
					if (oRWLock.IsReaderLockHeld)
					{
						// Check again to possibly avoid the upgrade
						if (AppUtils.StringEmpty(AppName)) 
						{
							oRWLock.UpgradeToWriterLock(CONST_WAIT_TIME_TO_AQUIRE);
							
							if (oRWLock.IsWriterLockHeld) 
								AppName = ConfigurationSettings.AppSettings.Get("ApplicationName").ToString();
							else
								throw new Exception("Unable to get Writer Lock on AppName");
						}
					}	
					else
						throw new Exception("Unable to aquire Reader Lock");
				} 
				finally 
				{	
					oRWLock.ReleaseLock();
				}
			}
		
			return AppName;
		}</pre>]]></content:encoded>
      <snippet:downloads>10</snippet:downloads>
      <snippet:rating>1</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=7cac81e2-e3e0-480f-a42b-ee7a1d62a6ee</guid>
      <title>C# : Proper Way to code a Factory as static in an Abstract Class (NOTE: Look for the StringEmpty Static to compile this)</title>
      <link>/PreviewSnippet.aspx?SnippetID=7cac81e2-e3e0-480f-a42b-ee7a1d62a6ee</link>
      <description>C# : Proper Way to code a Factory as static in an Abstract Class (NOTE: Look for the StringEmpty Static to compile this) [C#]</description>
      <author>Damon Carr</author>
      <pubDate>Sun, 24 Apr 2005 15:48:08 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=7cac81e2-e3e0-480f-a42b-ee7a1d62a6ee#comments</comments>
      <category>0f7510dd-92d6-4892-9539-4866adb651a3</category>
      <dc:title>C# : Proper Way to code a Factory as static in an Abstract Class (NOTE: Look for the StringEmpty Static to compile this)</dc:title>
      <dc:date>4/24/2005 3:48:08 PM</dc:date>
      <dc:creator>Damon Carr</dc:creator>
      <content:encoded><![CDATA[<pre>		public static Car GetCar(String CarType)
		{
			// NOTE: See the reference code for the static StringEmpty function
			// also uploaded. You are ThreadSafe because Strings are immutable and 
			// you have no risk of concurrent access or corruption as each thread has a dedicated 
			// parameter stack
			if (AppUtils.StringEmpty(CarType))
				throw new Exception("You must pass in a value to the GetCar factory. You passed in an empty string or null");
			object oCar = Activator.CreateInstance(Type.GetType(CarType));
			Car oCastCar = oCar as Car;
			if (oCastCar != null)
				return oCastCar;
			else
				throw new Exception("Invalid Cast. Type Requested does not implement the required interface");
		}
</pre>]]></content:encoded>
      <snippet:downloads>16</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
  </channel>
</rss>