Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 1.49 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. GetValue from list of GetProperties without an instantiated object using reflection
  2. public class SomeClass
  3. {
  4.     public IBy Some1{ get { return By.CssSelector("span[id$=spanEarth]"); } }
  5.  
  6.     public IBy Some2 { get { return By.CssSelector("span[id$=spanWorm]"); } }
  7.  
  8.     public IBy Some3 { get { return By.CssSelector("span[id$=spanJim]"); } }
  9. }
  10.        
  11. var gridRow = Type.GetType(typeof(SomeOtherClassInSameNamespace).AssemblyQualifiedName.Replace("SomeOtherClassInSameNamespace", "SomeClass"), true, true);
  12.  
  13. var rowList = gridRow.GetProperties().Where(p => p.PropertyType.Name.Contains("IBy")).ToList();
  14.  
  15. int i = 0;
  16. foreach (var property in rowList)
  17. {
  18.     string test = property.GetValue(gridRow, null).ToString();
  19. }
  20.        
  21. public class SomeClass
  22. {
  23.     public static IBy Some1 { get { return By.CssSelector("span[id$=spanEarth]"); } }
  24.  
  25.     public static IBy Some2 { get { return By.CssSelector("span[id$=spanWorm]"); } }
  26.  
  27.     public static IBy Some3 { get { return By.CssSelector("span[id$=spanJim]"); } }
  28. }
  29. ...
  30.  
  31. var gridRow = Type.GetType(typeof(SomeOtherClassInSameNamespace)
  32.                               .AssemblyQualifiedName
  33.                               .Replace("SomeOtherClassInSameNamespace", "SomeClass"),
  34.                            true, true);
  35. var rowList = gridRow.GetProperties(BindingFlags.Public | BindingFlags.Static)
  36.                      .Where(p => p.PropertyType.Name.Contains("IBy"));
  37.  
  38. int i = 0;
  39. foreach (var property in rowList)
  40. {
  41.     string test = property.GetValue(null, null).ToString();
  42.     ...
  43. }