1
汎用メソッドのコントラクトが失われ、ILに表示されません。以下はコード例です。非ジェネリックをインターフェイスから削除したばかりの場合、ジェネリックコントラクトは期待通りに機能します。しかし、ジェネリック医薬品の非ジェネリック医薬品の場合、ジェネリック医薬品は再発行で失われています。ジェネリックメソッドと非ジェネリックメソッドの名前とパラメータが同じ場合、コード契約1.4.40602.0のバグ?
[ContractClass(typeof(IContractTestContract))]
interface IContractTest
{
string TestMethod(string arg);
T TestMethod<T>(string arg);
}
[ContractClassFor(typeof(IContractTest))]
abstract class IContractTestContract : IContractTest
{
public string TestMethod(string arg)
{
Contract.Requires(!String.IsNullOrEmpty(arg));
throw new NotImplementedException();
}
public T TestMethod<T>(string arg)
{
Contract.Requires(!String.IsNullOrEmpty(arg));
throw new NotImplementedException();
}
}
class ContractTest : IContractTest
{
public string TestMethod(string arg) { return null; }
public T TestMethod<T>(string arg) { return default(T); }
}
class Program
{
static void Main(string[] args)
{
var c = new ContractTest();
//Does not fail static or runtime checks
//Contract is getting lost
c.TestMethod<string>(null);
}
}
コード契約セッティングは
MSRに報告しましたか? –
「コールサイトにチェックが必要です」を有効にしましたか?契約が発信者に組み込まれているため、行動が異なる可能性があります。 –
私は 'Call-site Requires Checking'を試しましたが、同じ動作をしています。契約は失われており、静的またはランタイムエラーは発生していません。はい、私はMicrosoftにこの問題を報告しました。 [Microsoft Connect](http://connect.microsoft.com/VisualStudio/feedback/details/712865/bug-in-code-contracts-1-4-40602-0-when-generic-and-non-generic-method -have-the-same-name-and-parameters)[コード契約フォーラム](http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/c74d7aa0-d7ed-47eb-9f5c-543a3b2a5a70 ) –