我正在将 Silverlight 4 与 VS 2010 一起使用并尝试对匿名类型进行反思,但我得到了一些“尝试通过方法'...'访问方法'...'失败。”。我为此尝试了各种解决方法,但找不到简单的解决方法。
class.CallAnonymous("SimpleClass", "HelloFunc", new { strIn = "Boo" });
public void CallAnonymous(string cName, string cAction, object anonymousParms)
{
Type anonymousType = anonymousParms.GetType();
PropertyInfo[] props = anonymousType.GetProperties();
ServiceParam serviceParam = new ServiceParam();
foreach (var info in props)
{
string propertyName = info.Name;
object propertyObj = info.GetValue(anonymousParms, null);
// Throw the exception on PropertyInfo.GetValue()
serviceParam.Add(propertyName, propertyObj);
}
}