Bir yöntemin hiçbir zaman bir null döndürmediğini nasıl anlarım? Şu anda bu benim kodum.Bir yöntemin hiçbir zaman kod sözleşmelerini kullanarak bir null döndürdüğünü nasıl gösterebilirim?
19 numaralı satır, CreateFunction, sonucun hiçbir şey olmadığını varsayarsa da, kanıtlanmış bir onay almaz.
1 <Pure()> Public Function CreateFunction(Of TArg1, TArg2, TResult)(ByVal body As Func(Of Expression, Expression, BinaryExpression)) As Func(Of TArg1, TArg2, TResult)
2 Contract.RequiresAlways(body IsNot Nothing)
3 Contract.Assume(Contract.Result(Of Func(Of TArg1, TArg2, TResult))() IsNot Nothing)
4
5 Dim arg1 = Expression.Parameter(GetType(Integer), "arg1")
6 Dim arg2 = Expression.Parameter(GetType(Integer), "arg2")
7
8
9 Dim temp = Expression.Lambda(body(arg1, arg2), arg1, arg2)
10 Contract.Assume(temp IsNot Nothing)
11 Return DirectCast(temp.Compile, Global.System.Func(Of TArg1, TArg2, TResult))
12 End Function
13
14 <Pure()> Public Function Add() As Func(Of T, T, T)
15 Contract.Ensures(Contract.Result(Of Func(Of T, T, T))() IsNot Nothing)
16
17 Dim temp = CreateFunction(Of T, T, T)(AddressOf Expression.AddChecked)
18 Return temp
19 End Function
Aynı yapıyı kullandım, bence doğru. Çok kötü OP cevap vermiyor. – mafu
Bu VB, bu yüzden 'Contract.Ensures (Contract.Result (Of Func (Of TArg1, TArg2, TResult)) olurdu.() IsNot Nothing) ' –