Activator.CreateInstance的其他合同 [英] Additional contracts on Activator.CreateInstance

查看:80
本文介绍了Activator.CreateInstance的其他合同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在
Activator中添加以下任一项保证.CreateInstance
方法:

Contract.Ensures(Contract.Result<object>().GetType() == type);

Contract.Ensures(type.IsInstanceOfType(Contract.Result<object>()));

我希望第一个应该没问题,但我不确定Activator.CreateInstance是否创建了一个不完全符合要求类型的Type。无论哪种方式,最好知道你要回来的物品实际上是你所要求的类型。

I am hoping the first one should be okay, but I am unsure whether Activator.CreateInstance ever creates a Type which is not exactly of the Type requested. Either way, it would be nice to know the item you are getting back is actually of the type you requested.

谢谢,

Luke

推荐答案

根据我的其他帖子,对这些额外的合同是否有任何想法?
As per my other thread, are there any thoughts on these additional contracts?


这篇关于Activator.CreateInstance的其他合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆