在合同中使用typeof() [英] Using typeof() in the Contract
本文介绍了在合同中使用typeof()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
我正在尝试 应用
合同 到通用 类型 a
方法 ,但静态检查CodeContract 显示
警告 (见代码)
I'm trying to apply the contract to a generic type of a method, but the Static Checking of CodeContract shows me a warning (see code)
class Program
{
static void Main()
{
// Warning: requires unproven: typeof(T).IsPrimitive || typeof(string).Equals(typeof(T))
execute<int>();
}
static void execute<T>()
{
// Warning: + location related to previous warning
Contract.Requires(typeof(T).IsPrimitive || typeof(string).Equals(typeof(T)));
}
}
推荐答案
嗨Denis,
Hi Denis,
对于那个很抱歉。目前,静态检查器没有对涉及typeof(和反射)的合同的强大支持。
sorry about that. At the moment, the static checker does not have a strong support for contracts involving typeof (and reflection).
您可以做的最好的事情是使用Suppressmessage属性来消除警告
The best you can do is shuting off the warning by using the Suppressmessage attribute
Ciao,
f
这篇关于在合同中使用typeof()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文