I would like to use reflection in .NET to access the object that called my method. I guess you can somehow view the stack. I know this is not safe for various reasons, but I just need to capture and catalog some property values.
How to do it?
Update : I'm an idiot, I forgot to say that it was in C #
var methodInfo = new StackFrame(1).GetMethod();
Returns a method that calls the current method.
, ( , ), . , :
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
, . emptor.
EDITED. , , . .
, ?
( ) , ?
StackTrace StackFrame
MSDN
http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe.aspx
, "Main"
class Program { static void Main(string[] args){ Func(); } static void Func(){ StackFrame frame = new StackFrame(1); StackTrace trace = new StackTrace(frame); var method = frame.GetMethod(); Console.WriteLine(method.Name); } }
Source: https://habr.com/ru/post/1714580/More articles:JQuery nearest () help - javascriptValidating a partial Rails table - validationШирины столбцов WPF DataGrid и переупорядочение - wpfSilverlight или ASP.NET - ajaxКак сделать инфраструктуру Entity Framework 2 и NHibernate? - entity-frameworkCan I use cURL to capture an html table? - phpPass the method to another method that requires a method name - .nethttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1714583/subsonic-using-shareddbconnectionscope-together-with-transactionscope-seems-to-be-broken&usg=ALkJrhiDo2x61Y0_iE9mhxRXVhmkH98RSQФизическое разделение среднего уровня для приложений Windows Forms - architectureserver.Transfer with query string - asp.netAll Articles