473,626 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatically generate a string of the namespace, class, function/procedure.

Is there anyway to generate a string that contains the name of the
namespace, the object name and then the function/procedure name that is
currently running.

I want to use this for logging information and am getting tired of having to
type/cut-paste the things.

If I can't get it all, can I get at least some of it?

TIA - Jeff.
Sep 12 '07 #1
2 1387
"Mufasa" <jb@nowhere.com wrote in message
news:O3******** ******@TK2MSFTN GP05.phx.gbl...
Is there anyway to generate a string that contains the name of the
namespace, the object name and then the function/procedure name that is
currently running.
You can use the StackTrace class to get the last StackFrame in the
stack. This has a GetMethod() method which will give you the information
that you want.

Note, however, that this is not a fast operation, so you will not want
to leave this permanently active inside your methods.

Sep 12 '07 #2
On Sep 12, 3:08 pm, "Mufasa" <j...@nowhere.c omwrote:
Is there anyway to generate a string that contains the name of the
namespace, the object name and then the function/procedure name that is
currently running.

I want to use this for logging information and am getting tired of having to
type/cut-paste the things.

If I can't get it all, can I get at least some of it?

TIA - Jeff.
Here is a C# example:
static void Main(string[] args)
{
System.Diagnost ics.StackFrame sf = new
System.Diagnost ics.StackFrame( true);
string fileName = sf.GetFileName( );
string lineNumber = sf.GetFileLineN umber().ToStrin g();
string methodName = sf.GetMethod(). Name;

string output = string.Format(" File name={0} , Line
number={1} , Method name={2}", fileName, lineNumber, methodName);
Console.WriteLi ne(output);
}

Sep 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2189
by: Filip Dreger | last post by:
Each function has a func_code property that is suposed to contain the pure bytecode of the function. All the context (including reference to relevant namespaces) is stored in different fields of the function object. Since 'exec' is able to execute any string or bytecode in the current scope, it would seem possible to execute code of any function in any namespace. But no matter how I tried, I could not do it. There must be something I am...
0
410
by: Daniel Lidström | last post by:
Hi, I've been trying a long time now to generate some XML using MC++ and XmlSerializer. I have a piece of C# code that produces exactly what I want, but I simply can't get the MC++ code to write the same thing. Below I have included two minimal compilable samples that illustrate my problem. The C# code produces this XML: <?xml version="1.0" encoding="utf-8"?>
2
6924
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and also a separate <Silcn:report> again off the root.
1
11221
by: Jeffrey B. Holtz | last post by:
I'm trying to get the Name of the USB device pluged in from the RegisterDeviceNotification that I've used P/Invoke to marshal. I have seen a similar posting on the VisualBasic newgroups but I do not know how to translate the ReDim that occurs there into C#. Or wither this will actually give me what I'm looking for. The code I'm posting seems to work although I don't know how to set the length of the name correctly in the...
7
7898
by: Steven.Xu | last post by:
Hello everyone! I have a problem about create an instance automatically in C#. Now I have a class: namespace1.namespace11.CClass01. I want to create it's instance in a function named CreateObjInstance. And the function not only generate just CClass01. So I must sent the class type(whit it's namespace) into the function. There has two question following. The first is I can't send a class type into function. It must is a object instance....
6
3365
by: cpnet | last post by:
I've authored a custom web component (a non-ui component kinda like a DataSet) and so far it's working. When my web component is added to the web form in the designer from the toolbox, the namespace for my component is automatically added to the using directive of the codebehind. And, the appropriate assembly is added to the "References" for the Web form's project. However, my custom component has a field (initialized to null, and...
0
5106
by: Richard Gregory | last post by:
Hi, I have the wsdl below, for an Axis web service, and when I select Add Web Refernce in Visual Studio the proxy is missing a class representing the returnedElementsType (see reference.cs below the wsdl). This complex type is a collection of another complex type(elementType), and the Reference.cs has an array of these rather than the single returnedElementsType. If If I want to be able to obtain these elements from the SOAP response I...
9
2091
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No, this is not a homework assignment. In fact it was a question on my class midterm that everyone bombed. Unfortunately we never covered this in class prior to the midterm. Anyway, please help if you would be so kind. Here is what I have. I...
8
7037
by: Les Caudle | last post by:
Using this command line to run XSD.exe xsd /c /o:outputDir input.xsd /f on the following XSD <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:dino="http://example.com/test" targetNamespace="http://example.com/test" elementFormDefault="qualified">
0
8259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6119
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1504
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.