PC Review


Reply
Thread Tools Rate Thread

What is the C# for this C++

 
 
newscorrespondent@charter.net
Guest
Posts: n/a
 
      17th Jun 2006

C++

void SomeClass::SomeRoutine (void)
{ QuestionClass abc(__FUNCTION__);
}

In C++ when "SomeRoutine" runs the QuestionClass gets the name of the
current function. It seems like I should be able to get this using
reflection with C# but I have not been able to figure out how. Is there a
way to do this?

When this routine ends the destructor for QuestionClass is run. Is there a
way in C# to insure that the class is destroyed in a similar fashion. The
best way I can see is to make the class implement IDisposable and use a
using clause wrapping the entire contents of the routine. Is there a better
way?

Thanks
 
Reply With Quote
 
 
 
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      17th Jun 2006
(E-Mail Removed) wrote:
> C++
>
> void SomeClass::SomeRoutine (void)
> { QuestionClass abc(__FUNCTION__);
> }
>
> In C++ when "SomeRoutine" runs the QuestionClass gets the name of the
> current function. It seems like I should be able to get this using
> reflection with C# but I have not been able to figure out how. Is
> there a way to do this?


See System.Environment.StackTrace or the System.Diagnostics.StackTrace
class. There's an example at

http://msdn2.microsoft.com/en-us/4ce0ktkk(VS.80).aspx

that shows how to get the current routine name using the StackTrace class.

>
> When this routine ends the destructor for QuestionClass is run. Is
> there a way in C# to insure that the class is destroyed in a similar
> fashion. The best way I can see is to make the class implement
> IDisposable and use a using clause wrapping the entire contents of
> the routine. Is there a better way?


No - that's the best you can do in C#.

-cd


 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      17th Jun 2006
(E-Mail Removed) wrote:

> C++
>
> void SomeClass::SomeRoutine (void)
> { QuestionClass abc(__FUNCTION__);
> }
>
> In C++ when "SomeRoutine" runs the QuestionClass gets the name of the
> current function. It seems like I should be able to get this using
> reflection with C# but I have not been able to figure out how. Is there a
> way to do this?


MethodBase.GetCurrentMethod()

> When this routine ends the destructor for QuestionClass is run. Is there a
> way in C# to insure that the class is destroyed in a similar fashion. The
> best way I can see is to make the class implement IDisposable and use a
> using clause wrapping the entire contents of the routine. Is there a better
> way?


No, that's the standard C# idiom for this.

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:25 AM.