Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get property name inside setter

I want to preserve a property between postbacks in an ASP.Net application. Currently doing this:

public int MyIndex {     get     {         return (int)Session[ToString() + "MyIndex"];     } } 

but would prefer something like:

public int MyIndex {     get     {         return (int)Session[ToString() + #code_that_returns_property_name#];     } } 

Setter omitted, but it just pushes value into Session using the same string. Is there some way to use reflection, or a different better solution?

like image 203
Steve Macdonald Avatar asked Jun 25 '09 15:06

Steve Macdonald


1 Answers

public static int Dummy {     get {         var propertyName = MethodBase.GetCurrentMethod().Name.Substring(4);         Console.WriteLine(propertyName);         return 0;     } } 
like image 190
sisve Avatar answered Sep 30 '22 10:09

sisve