code contracts - How do I tell in c# codecontracts that a external method never returns null? -


i have following piece of c# code:

myclaimsidentity.findfirst(claimtypes.nameidentifier).value; 

codecontract knows myclaimsidentity never null. complains findfirst(string) method might return null:

warning codecontracts: possibly calling method on null reference. expect system.security.claims.claimsidentity.findfirst(system.string) returns non-null?

i expect this, how can tell codechecker? of course can't change the findfirst(string) since comes external library.

the simple approach is:

var nameidentifier = myclaimsidentity.findfirst(claimtypes.nameidentifier); contract.assume(nameidentifier != null); nameidentifier.value; 

code contracts not try prove assume condition, use when proving other requirements.

it's possible create contract reference assembly external code has appropriate ensures post-conditions. code contracts team bcl types. don't know how that.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -