public class SomeClass
{
public IBy Some1{ get { return By.CssSelector("span[id$=spanEarth]"); } }
public IBy Some2 { get { return By.CssSelector("span[id$=spanWorm]"); } }
public IBy Some3 { get { return By.CssSelector("span[id$=spanJim]"); } }
}
是类,我以这种方式使用反射:
var gridRow = Type.GetType(typeof(SomeOtherClassInSameNamespace).AssemblyQualifiedName.Replace("SomeOtherClassInSameNamespace", "SomeClass"), true, true);
var rowList = gridRow.GetProperties().Where(p => p.PropertyType.Name.Contains("IBy")).ToList();
int i = 0;
foreach (var property in rowList)
{
string test = property.GetValue(gridRow, null).ToString();
}
这为 objectType 异常提供了运行时错误。如何使用反射从属性列表中获取值?