<p>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">On my current project we wished to impersonate a WebService for test purposes and decided to record live messages using XmlSerialization. For the first few messages I manually implemented code to serialize to a file. This cut-and-paste reuse obviously had to be refactored but I was unhappy manually passing in the filename to every call of the new method since the files are named the same as the webmethod. Somehow the generic serialization code needed to know who called it, or to put it in Jerry's terms it had to ask 'Were were I?'. <a href="http://weblogs.asp.net/jdennany/">Jerry</a> replied to my first ever blog post and finally I got a chance to use his suggestion:</span>
	</p>
	<p>
			<u>
					<span style="font-size:10pt;color:blue;font-family:Verdana;">
							<a href="http://dotnetworkaholic.com/PermaLink,guid,692ca362-89cb-4dad-985f-92aea92ca96b.aspx">http://dotnetworkaholic.com/PermaLink,guid,692ca362-89cb-4dad-985f-92aea92ca96b.aspx</a>
							<br />
					</span>
			</u>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">
					<a href="http://www.codeproject.com/csharp/customtracelistener.asp">http://www.codeproject.com/csharp/customtracelistener.asp</a>
					
					
			</span>
	</p>
	<p>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">The crux is the StackTrace class which resides in the System.Diagnostics namespace. It is exactly as you might expect - very simple when you know it exists but I believe it would be hard to find using Google etc.</span>
	</p>
	<p>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">This is the code snippet I used after re-reading Jerry's Code Project article:</span>
	</p>
	<p>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">   #region Get the calling method ("Where were I" - courtesy of Jerry Dennany)<br />   System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();<br />   string methodName = "unknown";<br />   if (st.FrameCount &gt; 0)<br />   {<br />    System.Diagnostics.StackFrame sf = st.GetFrame(1);<br />    methodName       = sf.GetMethod().Name;<br />   }<br />   #endregion</span>
	</p>
	<p>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">Being a stickler for simplicity I read the MSDN help and reduced the code to:</span>
	</p>
	<p>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">   #region Get the calling method name ("Where were I" - courtesy of Jerry Dennany)<br />   System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, false);<br />   string methodName = st.GetFrame(0).GetMethod().Name;<br />   #endregion</span>
	</p>
	<p>
			<span style="font-size:10pt;color:#003300;font-family:Verdana;">I am not sure that my employer will be sending a Mr. Dennany a check anytime soon, but I appreciated the helpful article. This is a good reminder of why we 'waste' so much time with blogs.</span>
	</p>
	<p class="MsoNormal" style="margin:0;">
			<span style="font-size:10pt;font-family:Arial;">
					
							<font color="#000000"> </font>
					
			</span>
	</p>
	<p> </p>