Obtain the namespace, class name, And Method Name of the current method or page.

Source: Internet
Author: User

Source Network:

 

         Public   Static   String Getmethodinfo ()
{
String STR = "" ;

// Get the namespace of the current method
STR + = " Namespace Name: " + System. reflection. methodbase. getcurrentmethod (). declaringtype. namespace +" \ N " ;

// Obtain the full name of the current method class, including the namespace
STR + = " Class Name: " + System. reflection. methodbase. getcurrentmethod (). declaringtype. fullname + " \ N " ;

// Get the current method name
STR + = " Method Name: " + System. reflection. methodbase. getcurrentmethod (). Name + " \ N " ; STR + = " \ N " ;

System. Diagnostics. stacktrace Ss = New System. Diagnostics. stacktrace ( True );
System. reflection. methodbase MB = ss. getframe ( 1 ). Getmethod ();

// Obtain the namespace of the parent Method
STR + = Mb. declaringtype. namespace + " \ N " ;

// Obtain the parent method class name
STR + = Mb. declaringtype. Name + " \ N " ;

// Obtain the full name of the parent method class.
STR + = Mb. declaringtype. fullname + " \ N " ;

// Obtain the parent method name
STR + = Mb. Name + " \ N " ; Return STR;
}

Package not only the current method, namespace, class name, And Method Name of the current page, but also the namespace, class name, and method name of the parent class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.