43 | /// [CanBeNull] object Test() => null;
44 | ///
45 | /// void UseTest() {
46 | /// var p = Test();
47 | /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
48 | /// }
49 | ///
50 | ///
64 | /// [NotNull] object Foo() {
65 | /// return null; // Warning: Possible 'null' assignment
66 | /// }
67 | ///
68 | ///
84 | /// public void Foo([ItemNotNull]List<string> books)
85 | /// {
86 | /// foreach (var book in books) {
87 | /// if (book != null) // Warning: Expression is always true
88 | /// Console.WriteLine(book.ToUpper());
89 | /// }
90 | /// }
91 | ///
92 | ///
107 | /// public void Foo([ItemCanBeNull]List<string> books)
108 | /// {
109 | /// foreach (var book in books)
110 | /// {
111 | /// // Warning: Possible 'System.NullReferenceException'
112 | /// Console.WriteLine(book.ToUpper());
113 | /// }
114 | /// }
115 | ///
116 | ///
131 | /// [StringFormatMethod("message")]
132 | /// void ShowError(string message, params object[] args) { /* do something */ }
133 | ///
134 | /// void Foo() {
135 | /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string
136 | /// }
137 | ///
138 | ///
162 | /// namespace TestNamespace
163 | /// {
164 | /// public class Constants
165 | /// {
166 | /// public static int INT_CONST = 1;
167 | /// public const string STRING_CONST = "1";
168 | /// }
169 | ///
170 | /// public class Class1
171 | /// {
172 | /// [ValueProvider("TestNamespace.Constants")] public int myField;
173 | /// public void Foo([ValueProvider("TestNamespace.Constants")] string str) { }
174 | ///
175 | /// public void Test()
176 | /// {
177 | /// Foo(/*try completion here*/);//
178 | /// myField = /*try completion here*/
179 | /// }
180 | /// }
181 | /// }
182 | ///
183 | ///
204 | /// void Foo(string param) {
205 | /// if (param == null)
206 | /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
207 | /// }
208 | ///
209 | ///
242 | /// public class Foo : INotifyPropertyChanged {
243 | /// public event PropertyChangedEventHandler PropertyChanged;
244 | ///
245 | /// [NotifyPropertyChangedInvocator]
246 | /// protected virtual void NotifyChanged(string propertyName) { ... }
247 | ///
248 | /// string _name;
249 | ///
250 | /// public string Name {
251 | /// get { return _name; }
252 | /// set { _name = value; NotifyChanged("LastName"); /* Warning */ }
253 | /// }
254 | /// }
255 | ///
256 | /// Examples of generated notifications:
257 | /// Function Definition Table syntax:
292 | ///
311 | /// [ContractAnnotation("=> halt")]
312 | /// public void TerminationMethod()
313 | ///
314 | ///
317 | /// [ContractAnnotation("null <= param:null")] // reverse condition syntax
318 | /// public string GetName(string surname)
319 | ///
320 | ///
323 | /// [ContractAnnotation("s:null => true")]
324 | /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty()
325 | ///
326 | ///
329 | /// // A method that returns null if the parameter is null,
330 | /// // and not null if the parameter is not null
331 | /// [ContractAnnotation("null => null; notnull => notnull")]
332 | /// public object Transform(object data)
333 | ///
334 | ///
337 | /// [ContractAnnotation("=> true, result: notnull; => false, result: null")]
338 | /// public bool TryParse(string s, out Person result)
339 | ///
340 | ///
367 | /// [LocalizationRequiredAttribute(true)]
368 | /// class Foo {
369 | /// string str = "my string"; // Warning: Localizable string
370 | /// }
371 | ///
372 | ///
396 | /// [CannotApplyEqualityOperator]
397 | /// class NoEquality { }
398 | ///
399 | /// class UsesNoEquality {
400 | /// void Test() {
401 | /// var ca1 = new NoEquality();
402 | /// var ca2 = new NoEquality();
403 | /// if (ca1 != null) { // OK
404 | /// bool condition = ca1 == ca2; // Warning
405 | /// }
406 | /// }
407 | /// }
408 | ///
409 | ///
421 | /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement
422 | /// class ComponentAttribute : Attribute { }
423 | ///
424 | /// [Component] // ComponentAttribute requires implementing IComponent interface
425 | /// class MyComponent : IComponent { }
426 | ///
427 | ///
587 | /// [Pure] int Multiply(int x, int y) => x * y;
588 | ///
589 | /// void M() {
590 | /// Multiply(123, 42); // Waring: Return value of pure method is not used
591 | /// }
592 | ///
593 | /// [MustUseReturnValue("Use the return value to...")]
.
609 | ///
632 | /// class Foo {
633 | /// [ProvidesContext] IBarService _barService = ...;
634 | ///
635 | /// void ProcessNode(INode node) {
636 | /// DoSomething(node, node.GetGlobalServices().Bar);
637 | /// // ^ Warning: use value of '_barService' field
638 | /// }
639 | /// }
640 | ///
641 | ///
684 | /// [SourceTemplate]
685 | /// public static void forEach<T>(this IEnumerable<T> xs) {
686 | /// foreach (var x in xs) {
687 | /// //$ $END$
688 | /// }
689 | /// }
690 | ///
691 | ///
709 | /// [SourceTemplate, Macro(Target = "item", Expression = "suggestVariableName()")]
710 | /// public static void forEach<T>(this IEnumerable<T> collection) {
711 | /// foreach (var item in collection) {
712 | /// //$ $END$
713 | /// }
714 | /// }
715 | ///
716 | /// Applying the attribute on a template method parameter:
717 | ///
718 | /// [SourceTemplate]
719 | /// public static void something(this Entity x, [Macro(Expression = "guid()", Editable = -1)] string newguid) {
720 | /// /*$ var $x$Id = "$newguid$" + x.ToString();
721 | /// x.DoSomething($x$Id); */
722 | /// }
723 | ///
724 | ///
994 | /// [ActionName("Foo")]
995 | /// public ActionResult Login(string returnUrl) {
996 | /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK
997 | /// return RedirectToAction("Bar"); // Error: Cannot resolve action
998 | /// }
999 | ///
1000 | ///
1052 | /// public class MyStringCollection : List<string>
1053 | /// {
1054 | /// [CollectionAccess(CollectionAccessType.Read)]
1055 | /// public string GetFirstString()
1056 | /// {
1057 | /// return this.ElementAt(0);
1058 | /// }
1059 | /// }
1060 | /// class Test
1061 | /// {
1062 | /// public void Foo()
1063 | /// {
1064 | /// // Warning: Contents of the collection is never updated
1065 | /// var col = new MyStringCollection();
1066 | /// string x = col.GetFirstString();
1067 | /// }
1068 | /// }
1069 | ///
1070 | ///
1173 | /// static void ThrowIfNull<T>([NoEnumeration] T v, string n) where T : class
1174 | /// {
1175 | /// // custom check for null but no enumeration
1176 | /// }
1177 | ///
1178 | /// void Foo(IEnumerable<string> values)
1179 | /// {
1180 | /// ThrowIfNull(values, nameof(values));
1181 | /// var x = values.ToList(); // No warnings about multiple enumeration
1182 | /// }
1183 | ///
1184 | ///