18 | /// [CanBeNull] public object Test() { return null; }
19 | /// public void UseTest() {
20 | /// var p = Test();
21 | /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
22 | /// }
23 | ///
34 | /// [NotNull] public object Foo() {
35 | /// return null; // Warning: Possible 'null' assignment
36 | /// }
37 | ///
50 | /// [StringFormatMethod("message")]
51 | /// public void ShowError(string message, params object[] args) { /* do something */ }
52 | /// public void Foo() {
53 | /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string
54 | /// }
55 | ///
78 | /// public void Foo(string param) {
79 | /// if (param == null)
80 | /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
81 | /// }
82 | ///
102 | /// public class Foo : INotifyPropertyChanged {
103 | /// public event PropertyChangedEventHandler PropertyChanged;
104 | /// [NotifyPropertyChangedInvocator]
105 | /// protected virtual void NotifyChanged(string propertyName) { ... }
106 | ///
107 | /// private string _name;
108 | /// public string Name {
109 | /// get { return _name; }
110 | /// set { _name = value; NotifyChanged("LastName"); /* Warning */ }
111 | /// }
112 | /// }
113 | ///
114 | /// Examples of generated notifications:
115 | /// Function Definition Table syntax:
139 | ///
155 | /// [ContractAnnotation("=> halt")]
156 | /// public void TerminationMethod()
157 | ///
159 | /// [ContractAnnotation("halt <= condition: false")]
160 | /// public void Assert(bool condition, string text) // regular assertion method
161 | ///
163 | /// [ContractAnnotation("s:null => true")]
164 | /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty()
165 | ///
167 | /// // A method that returns null if the parameter is null, and not null if the parameter is not null
168 | /// [ContractAnnotation("null => null; notnull => notnull")]
169 | /// public object Transform(object data)
170 | ///
172 | /// [ContractAnnotation("s:null=>false; =>true,result:notnull; =>false, result:null")]
173 | /// public bool TryParse(string s, out Person result)
174 | ///
196 | /// [LocalizationRequiredAttribute(true)]
197 | /// public class Foo {
198 | /// private string str = "my string"; // Warning: Localizable string
199 | /// }
200 | ///
220 | /// [CannotApplyEqualityOperator]
221 | /// class NoEquality { }
222 | /// class UsesNoEquality {
223 | /// public void Test() {
224 | /// var ca1 = new NoEquality();
225 | /// var ca2 = new NoEquality();
226 | /// if (ca1 != null) { // OK
227 | /// bool condition = ca1 == ca2; // Warning
228 | /// }
229 | /// }
230 | /// }
231 | ///
242 | /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement
243 | /// public class ComponentAttribute : Attribute { }
244 | /// [Component] // ComponentAttribute requires implementing IComponent interface
245 | /// public class MyComponent : IComponent { }
246 | ///
379 | /// [Pure] private int Multiply(int x, int y) { return x * y; }
380 | /// public void Foo() {
381 | /// const int a = 2, b = 2;
382 | /// Multiply(a, b); // Waring: Return value of pure method is not used
383 | /// }
384 | ///
532 | /// [ActionName("Foo")]
533 | /// public ActionResult Login(string returnUrl) {
534 | /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK
535 | /// return RedirectToAction("Bar"); // Error: Cannot resolve action
536 | /// }
537 | ///