When you specify an
When using this constructor, you must be aware of a possible misuse of the constructor which takes a DbType parameter.
- This happens when calling this constructor passing an int 0 and the compiler thinks you are passing a value of DbType.
- Use Convert.ToInt32(value)
for example to have compiler calling the correct constructor.
- [CanBeNull] public object Test() { return null; }
- public void UseTest() {
- var p = Test();
- var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
- }
-
- [NotNull] public object Foo() {
- return null; // Warning: Possible 'null' assignment
- }
-
Function Definition Table syntax:
-
- [ContractAnnotation("=> halt")]
- public void TerminationMethod()
-
- [ContractAnnotation("halt <= condition: false")]
- public void Assert(bool condition, string text) // regular assertion method
-
- [ContractAnnotation("s:null => true")]
- public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty()
-
- // A method that returns null if the parameter is null,
- // and not null if the parameter is not null
- [ContractAnnotation("null => null; notnull => notnull")]
- public object Transform(object data)
-
- [ContractAnnotation("s:null=>false; =>true,result:notnull; =>false, result:null")]
- public bool TryParse(string s, out Person result)
-
- public void Foo(string param) {
- if (param == null)
- throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
- }
-