27 | /// [LocalizationRequiredAttribute(true)]
28 | /// public class Foo
29 | /// {
30 | /// private string str = "my string"; // Warning: Localizable string
31 | /// }
32 | ///
33 | ///
90 | /// [StringFormatMethod("message")]
91 | /// public void ShowError(string message, params object[] args)
92 | /// {
93 | /// //Do something
94 | /// }
95 | /// public void Foo()
96 | /// {
97 | /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string
98 | /// }
99 | ///
100 | ///
126 | /// public void Foo(string param)
127 | /// {
128 | /// if (param == null)
129 | /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
130 | /// }
131 | ///
132 | ///
153 | /// public class Foo : INotifyPropertyChanged
154 | /// {
155 | /// public event PropertyChangedEventHandler PropertyChanged;
156 | ///
157 | /// [NotifyPropertyChangedInvocator]
158 | /// protected virtual void NotifyChanged(string propertyName)
159 | /// {}
160 | ///
161 | /// private string _name;
162 | /// public string Name
163 | /// {
164 | /// get { return _name; }
165 | /// set
166 | /// {
167 | /// _name = value;
168 | /// NotifyChanged("LastName"); // Warning
169 | /// }
170 | /// }
171 | /// }
172 | ///
173 | /// Examples of generated notifications:
174 | ///
199 | /// [CanBeNull]
200 | /// public object Test()
201 | /// {
202 | /// return null;
203 | /// }
204 | ///
205 | /// public void UseTest()
206 | /// {
207 | /// var p = Test();
208 | /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
209 | /// }
210 | ///
211 | ///
220 | /// [NotNull]
221 | /// public object Foo()
222 | /// {
223 | /// return null; // Warning: Possible 'null' assignment
224 | /// }
225 | ///
226 | /// Function Definition Table syntax:
235 | ///
250 | /// [ContractAnnotation("=> halt")]
251 | /// public void TerminationMethod()
252 | ///
254 | /// [ContractAnnotation("halt <= condition: false")]
255 | /// public void Assert(bool condition, string text) // Regular Assertion method
256 | ///
258 | /// [ContractAnnotation("s:null => true")]
259 | /// public bool IsNullOrEmpty(string s) // String.IsNullOrEmpty
260 | ///
262 | /// // A method that returns null if the parameter is null, and not null if the parameter is not null
263 | /// [ContractAnnotation("null => null; notnull => notnull")]
264 | /// public object Transform(object data)
265 | ///
267 | /// [ContractAnnotation("s:null=>false; =>true,result:notnull; =>false, result:null")]
268 | /// public bool TryParse(string s, out Person result)
269 | ///
296 | /// [CannotApplyEqualityOperator]
297 | /// class NoEquality
298 | /// {
299 | /// }
300 | ///
301 | /// class UsesNoEquality
302 | /// {
303 | /// public void Test()
304 | /// {
305 | /// var ca1 = new NoEquality();
306 | /// var ca2 = new NoEquality();
307 | ///
308 | /// if (ca1 != null) // OK
309 | /// {
310 | /// bool condition = ca1 == ca2; // Warning
311 | /// }
312 | /// }
313 | /// }
314 | ///
315 | ///
325 | /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement
326 | /// public class ComponentAttribute : Attribute
327 | /// {}
328 | ///
329 | /// [Component] // ComponentAttribute requires implementing IComponent interface
330 | /// public class MyComponent : IComponent
331 | /// {}
332 | ///
333 | ///
490 | /// [Pure]
491 | /// private int Multiply(int x, int y)
492 | /// {
493 | /// return x*y;
494 | /// }
495 | ///
496 | /// public void Foo()
497 | /// {
498 | /// const int a=2, b=2;
499 | /// Multiply(a, b); // Waring: Return value of pure method is not used
500 | /// }
501 | ///
502 | ///
644 | /// [ActionName("Foo")]
645 | /// public ActionResult Login(string returnUrl)
646 | /// {
647 | /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK
648 | /// return RedirectToAction("Bar"); // Error: Cannot resolve action
649 | /// }
650 | ///
651 | ///