воскресенье, 24 октября 2021 г.

TypeName, Method, Reflection

https://stackoverflow.com/questions/2113069/c-sharp-getting-its-own-class-name

this.GetType().Name
protected string GetThisClassName() { return this.GetType().Name;

public static class Extension
{
    public static string NameOf(this object o)
    {
        return o.GetType().Name;
    }
}

And then use like this:

public class MyProgram
{
    string thisClassName;

    public MyProgram()
    {
        this.thisClassName = this.NameOf();
    }
}
string CurrentClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name.ToString();
string CurrentClass = System.Reflection.MethodBase.GetCurrentMethod().Name.ToString();






Комментариев нет:

Отправить комментарий