Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2007, 07:30 AM
Registered User
 
Join Date: Sep 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# version of C predefined macros __LINE__

Is there an equivalent to the C predefined macros of __FILE__
and __LINE__.

in C I could do report do something like this:

    errLog(__FILE__, __LINE__);

This was very useful in determining unusual behavior.

Thanks
Jlr


 
Old April 6th, 2007, 08:18 AM
Authorized User
 
Join Date: Mar 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For a few solutions you can view this thread:
http://www.dotnet247.com/247reference/msgs/1/8826.aspx

Quote:
quote:
Code:
class SomeClass
{
   public void DoSomething()
   {
      ReportError("This is an error description");
   }

   private void ReportError()
   {
      StackFrame CallStack = new StackFrame(1, true);

      // This will report the line number and file name of the original ReportError call!
      MyWriteToLog("Error: " + Message + ", File: " + CallStack.GetFileName() + ", Line: " + CallStack.GetFileLineNumber());
   }

   private void MyWriteToLog(string LogMessage)
   {
      // Write LogMessage to some persistent log
   }
}
 
Old April 11th, 2007, 07:47 PM
Registered User
 
Join Date: Sep 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This suggestion is done at runtime not at compile time

Also I do not think that this will operate correctly if not in debug mode.

The thread that was recommended makes the same points.







Similar Threads
Thread Thread Starter Forum Replies Last Post
output xsl in predefined template newuser2525 XSLT 1 December 24th, 2007 08:30 AM
for-each loop predefined number of times vonkeldoos XSLT 1 February 22nd, 2007 07:47 AM
predefined forms Richard Access VBA 4 May 24th, 2004 12:57 PM
PreDefined Event Handler mark C# 1 June 7th, 2003 04:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.