c# - How does visual studio (or Resharper ?) know that "Expression is always true"? -


this question has answer here:

using visual studio 2012 resharper.

sample code:

    public void dosomethingwithtable(datatable dt)     {         if (dt.primarykey != null) // xx         {             //         }     } 

in ide, warning: "expression true" @ line marked xx. question is, how ide (or resharper ?) know datacolumn[] value of primarykey not null ?

i know if used tool reflector see inner workings of ado.net, come same conclusion, how resharper ? such warnings 100% reliable ?

i don't have reflector, maybe uses decompiler?

it can indeed never null, decompiled via ilspy:

public datacolumn[] primarykey {         {         uniqueconstraint uniqueconstraint = this.primarykey;         if (uniqueconstraint != null)         {             return uniqueconstraint.key.toarray();         }         return datatable.zerocolumns;     }         // setter ...  // system.data.datatable internal static readonly datacolumn[] zerocolumns = new datacolumn[0]; 

edit: shown in duplicate resharper uses notnullattribute classes in .net- or nunit framework.

we have analyzed great share of .net framework class library, nunit framework, , annotated through external xml files, using set of custom attributes jetbrains.annotations namespace....


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -