PropertyInfo.SetValue类型问题

Kation Kation 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

public class Test
{
private object _A;
public string A
{
get
{
if (_A is Binding)
return (string)((Binding)_A).GetValue();
return (string)_A;
}
set
{
_A = value;
}
}
}

public class Binding
{
public object GetValue() { return null; }
}


static void Main(string[] args)
{
Test test = new Test();
typeof(Test).GetProperty("A").SetValue(test, new Binding());
//报错
}

以上反射会先检查类型,直接报错。如何解决?
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
Kation
C# 111,129 成员 642,540 内容