我在VS 2010中使用Silverlight 4并尝试在匿名类型上做反射,并且我得到了一些“尝试按方法'...'来访问方法'...'失败“。我尝试了各种解决方法,但我找不到和简单的。反射失败的属性在Silverlight中的匿名类型
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);
}
}