c# - How do I cast a concatenated string to a Class.Property? -


i have static class several static strings used store constant values. example, foo.bar might return string representing database column name , foo.foo might return string epoch value.

in application, need concatenate class name name of string value need. example, know class name foo. know property name bar. property name changes based on value. in foreach, i'm concatenating class name other property name string "foo.bar". far we're okay. when pass concatenated string method takes string, not retrieve static string class. in other words, though concatenated string formed correctly "foo.bar", method not return value of foo.bar. if hardcode foo.bar string need needs done runtime.

any thoughts on how can fix this? can cast something?

public static class foo {     public static string bar = "sample text"; }  public class program {     static void main()     {       // string "foo.bar" built here combining 2 strings.       ...      // more processing      ...       // need literal value of foo.bar here not literally "foo.bar"...       } } 

if foo class, pass in name of property instead of concatenated string:

public string getstring(string propertyname) {     return typeof(foo).getproperty(propertyname).getvalue(null, null); } 

if it's not foo, pass in type getstring() method also.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -