Annotations.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /* MIT License
  2. Copyright (c) 2016 JetBrains http://www.jetbrains.com
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE. */
  18. using System;
  19. // ReSharper disable InheritdocConsiderUsage
  20. #pragma warning disable 1591
  21. // ReSharper disable UnusedMember.Global
  22. // ReSharper disable MemberCanBePrivate.Global
  23. // ReSharper disable UnusedAutoPropertyAccessor.Global
  24. // ReSharper disable IntroduceOptionalParameters.Global
  25. // ReSharper disable MemberCanBeProtected.Global
  26. // ReSharper disable InconsistentNaming
  27. namespace MECF.Framework.UI.Client.Annotations
  28. {
  29. /// <summary>
  30. /// Indicates that the value of the marked element could be <c>null</c> sometimes,
  31. /// so checking for <c>null</c> is required before its usage.
  32. /// </summary>
  33. /// <example><code>
  34. /// [CanBeNull] object Test() => null;
  35. ///
  36. /// void UseTest() {
  37. /// var p = Test();
  38. /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
  39. /// }
  40. /// </code></example>
  41. [AttributeUsage(
  42. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  43. AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event |
  44. AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)]
  45. public sealed class CanBeNullAttribute : Attribute { }
  46. /// <summary>
  47. /// Indicates that the value of the marked element can never be <c>null</c>.
  48. /// </summary>
  49. /// <example><code>
  50. /// [NotNull] object Foo() {
  51. /// return null; // Warning: Possible 'null' assignment
  52. /// }
  53. /// </code></example>
  54. [AttributeUsage(
  55. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  56. AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event |
  57. AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)]
  58. public sealed class NotNullAttribute : Attribute { }
  59. /// <summary>
  60. /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task
  61. /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property
  62. /// or of the Lazy.Value property can never be null.
  63. /// </summary>
  64. /// <example><code>
  65. /// public void Foo([ItemNotNull]List&lt;string&gt; books)
  66. /// {
  67. /// foreach (var book in books) {
  68. /// if (book != null) // Warning: Expression is always true
  69. /// Console.WriteLine(book.ToUpper());
  70. /// }
  71. /// }
  72. /// </code></example>
  73. [AttributeUsage(
  74. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  75. AttributeTargets.Delegate | AttributeTargets.Field)]
  76. public sealed class ItemNotNullAttribute : Attribute { }
  77. /// <summary>
  78. /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task
  79. /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property
  80. /// or of the Lazy.Value property can be null.
  81. /// </summary>
  82. /// <example><code>
  83. /// public void Foo([ItemCanBeNull]List&lt;string&gt; books)
  84. /// {
  85. /// foreach (var book in books)
  86. /// {
  87. /// // Warning: Possible 'System.NullReferenceException'
  88. /// Console.WriteLine(book.ToUpper());
  89. /// }
  90. /// }
  91. /// </code></example>
  92. [AttributeUsage(
  93. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  94. AttributeTargets.Delegate | AttributeTargets.Field)]
  95. public sealed class ItemCanBeNullAttribute : Attribute { }
  96. /// <summary>
  97. /// Indicates that the marked method builds string by the format pattern and (optional) arguments.
  98. /// The parameter, which contains the format string, should be given in constructor. The format string
  99. /// should be in <see cref="string.Format(IFormatProvider,string,object[])"/>-like form.
  100. /// </summary>
  101. /// <example><code>
  102. /// [StringFormatMethod("message")]
  103. /// void ShowError(string message, params object[] args) { /* do something */ }
  104. ///
  105. /// void Foo() {
  106. /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string
  107. /// }
  108. /// </code></example>
  109. [AttributeUsage(
  110. AttributeTargets.Constructor | AttributeTargets.Method |
  111. AttributeTargets.Property | AttributeTargets.Delegate)]
  112. public sealed class StringFormatMethodAttribute : Attribute
  113. {
  114. /// <param name="formatParameterName">
  115. /// Specifies which parameter of an annotated method should be treated as the format string
  116. /// </param>
  117. public StringFormatMethodAttribute([NotNull] string formatParameterName)
  118. {
  119. FormatParameterName = formatParameterName;
  120. }
  121. [NotNull] public string FormatParameterName { get; }
  122. }
  123. /// <summary>
  124. /// Use this annotation to specify a type that contains static or const fields
  125. /// with values for the annotated property/field/parameter.
  126. /// The specified type will be used to improve completion suggestions.
  127. /// </summary>
  128. /// <example><code>
  129. /// namespace TestNamespace
  130. /// {
  131. /// public class Constants
  132. /// {
  133. /// public static int INT_CONST = 1;
  134. /// public const string STRING_CONST = "1";
  135. /// }
  136. ///
  137. /// public class Class1
  138. /// {
  139. /// [ValueProvider("TestNamespace.Constants")] public int myField;
  140. /// public void Foo([ValueProvider("TestNamespace.Constants")] string str) { }
  141. ///
  142. /// public void Test()
  143. /// {
  144. /// Foo(/*try completion here*/);//
  145. /// myField = /*try completion here*/
  146. /// }
  147. /// }
  148. /// }
  149. /// </code></example>
  150. [AttributeUsage(
  151. AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field,
  152. AllowMultiple = true)]
  153. public sealed class ValueProviderAttribute : Attribute
  154. {
  155. public ValueProviderAttribute([NotNull] string name)
  156. {
  157. Name = name;
  158. }
  159. [NotNull] public string Name { get; }
  160. }
  161. /// <summary>
  162. /// Indicates that the integral value falls into the specified interval.
  163. /// It's allowed to specify multiple non-intersecting intervals.
  164. /// Values of interval boundaries are inclusive.
  165. /// </summary>
  166. /// <example><code>
  167. /// void Foo([ValueRange(0, 100)] int value) {
  168. /// if (value == -1) { // Warning: Expression is always 'false'
  169. /// ...
  170. /// }
  171. /// }
  172. /// </code></example>
  173. [AttributeUsage(
  174. AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property |
  175. AttributeTargets.Method | AttributeTargets.Delegate,
  176. AllowMultiple = true)]
  177. public sealed class ValueRangeAttribute : Attribute
  178. {
  179. public object From { get; }
  180. public object To { get; }
  181. public ValueRangeAttribute(long from, long to)
  182. {
  183. From = from;
  184. To = to;
  185. }
  186. public ValueRangeAttribute(ulong from, ulong to)
  187. {
  188. From = from;
  189. To = to;
  190. }
  191. public ValueRangeAttribute(long value)
  192. {
  193. From = To = value;
  194. }
  195. public ValueRangeAttribute(ulong value)
  196. {
  197. From = To = value;
  198. }
  199. }
  200. /// <summary>
  201. /// Indicates that the integral value never falls below zero.
  202. /// </summary>
  203. /// <example><code>
  204. /// void Foo([NonNegativeValue] int value) {
  205. /// if (value == -1) { // Warning: Expression is always 'false'
  206. /// ...
  207. /// }
  208. /// }
  209. /// </code></example>
  210. [AttributeUsage(
  211. AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property |
  212. AttributeTargets.Method | AttributeTargets.Delegate)]
  213. public sealed class NonNegativeValueAttribute : Attribute { }
  214. /// <summary>
  215. /// Indicates that the function argument should be a string literal and match one
  216. /// of the parameters of the caller function. For example, ReSharper annotates
  217. /// the parameter of <see cref="System.ArgumentNullException"/>.
  218. /// </summary>
  219. /// <example><code>
  220. /// void Foo(string param) {
  221. /// if (param == null)
  222. /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
  223. /// }
  224. /// </code></example>
  225. [AttributeUsage(AttributeTargets.Parameter)]
  226. public sealed class InvokerParameterNameAttribute : Attribute { }
  227. /// <summary>
  228. /// Indicates that the method is contained in a type that implements
  229. /// <c>System.ComponentModel.INotifyPropertyChanged</c> interface and this method
  230. /// is used to notify that some property value changed.
  231. /// </summary>
  232. /// <remarks>
  233. /// The method should be non-static and conform to one of the supported signatures:
  234. /// <list>
  235. /// <item><c>NotifyChanged(string)</c></item>
  236. /// <item><c>NotifyChanged(params string[])</c></item>
  237. /// <item><c>NotifyChanged{T}(Expression{Func{T}})</c></item>
  238. /// <item><c>NotifyChanged{T,U}(Expression{Func{T,U}})</c></item>
  239. /// <item><c>SetProperty{T}(ref T, T, string)</c></item>
  240. /// </list>
  241. /// </remarks>
  242. /// <example><code>
  243. /// public class Foo : INotifyPropertyChanged {
  244. /// public event PropertyChangedEventHandler PropertyChanged;
  245. ///
  246. /// [NotifyPropertyChangedInvocator]
  247. /// protected virtual void NotifyChanged(string propertyName) { ... }
  248. ///
  249. /// string _name;
  250. ///
  251. /// public string Name {
  252. /// get { return _name; }
  253. /// set { _name = value; NotifyChanged("LastName"); /* Warning */ }
  254. /// }
  255. /// }
  256. /// </code>
  257. /// Examples of generated notifications:
  258. /// <list>
  259. /// <item><c>NotifyChanged("Property")</c></item>
  260. /// <item><c>NotifyChanged(() =&gt; Property)</c></item>
  261. /// <item><c>NotifyChanged((VM x) =&gt; x.Property)</c></item>
  262. /// <item><c>SetProperty(ref myField, value, "Property")</c></item>
  263. /// </list>
  264. /// </example>
  265. [AttributeUsage(AttributeTargets.Method)]
  266. public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute
  267. {
  268. public NotifyPropertyChangedInvocatorAttribute() { }
  269. public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName)
  270. {
  271. ParameterName = parameterName;
  272. }
  273. [CanBeNull] public string ParameterName { get; }
  274. }
  275. /// <summary>
  276. /// Describes dependency between method input and output.
  277. /// </summary>
  278. /// <syntax>
  279. /// <p>Function Definition Table syntax:</p>
  280. /// <list>
  281. /// <item>FDT ::= FDTRow [;FDTRow]*</item>
  282. /// <item>FDTRow ::= Input =&gt; Output | Output &lt;= Input</item>
  283. /// <item>Input ::= ParameterName: Value [, Input]*</item>
  284. /// <item>Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value}</item>
  285. /// <item>Value ::= true | false | null | notnull | canbenull</item>
  286. /// </list>
  287. /// If the method has a single input parameter, its name could be omitted.<br/>
  288. /// Using <c>halt</c> (or <c>void</c>/<c>nothing</c>, which is the same) for the method output
  289. /// means that the method doesn't return normally (throws or terminates the process).<br/>
  290. /// Value <c>canbenull</c> is only applicable for output parameters.<br/>
  291. /// You can use multiple <c>[ContractAnnotation]</c> for each FDT row, or use single attribute
  292. /// with rows separated by semicolon. There is no notion of order rows, all rows are checked
  293. /// for applicability and applied per each program state tracked by the analysis engine.<br/>
  294. /// </syntax>
  295. /// <examples><list>
  296. /// <item><code>
  297. /// [ContractAnnotation("=&gt; halt")]
  298. /// public void TerminationMethod()
  299. /// </code></item>
  300. /// <item><code>
  301. /// [ContractAnnotation("null &lt;= param:null")] // reverse condition syntax
  302. /// public string GetName(string surname)
  303. /// </code></item>
  304. /// <item><code>
  305. /// [ContractAnnotation("s:null =&gt; true")]
  306. /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty()
  307. /// </code></item>
  308. /// <item><code>
  309. /// // A method that returns null if the parameter is null,
  310. /// // and not null if the parameter is not null
  311. /// [ContractAnnotation("null =&gt; null; notnull =&gt; notnull")]
  312. /// public object Transform(object data)
  313. /// </code></item>
  314. /// <item><code>
  315. /// [ContractAnnotation("=&gt; true, result: notnull; =&gt; false, result: null")]
  316. /// public bool TryParse(string s, out Person result)
  317. /// </code></item>
  318. /// </list></examples>
  319. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
  320. public sealed class ContractAnnotationAttribute : Attribute
  321. {
  322. public ContractAnnotationAttribute([NotNull] string contract)
  323. : this(contract, false) { }
  324. public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates)
  325. {
  326. Contract = contract;
  327. ForceFullStates = forceFullStates;
  328. }
  329. [NotNull] public string Contract { get; }
  330. public bool ForceFullStates { get; }
  331. }
  332. /// <summary>
  333. /// Indicates whether the marked element should be localized.
  334. /// </summary>
  335. /// <example><code>
  336. /// [LocalizationRequiredAttribute(true)]
  337. /// class Foo {
  338. /// string str = "my string"; // Warning: Localizable string
  339. /// }
  340. /// </code></example>
  341. [AttributeUsage(AttributeTargets.All)]
  342. public sealed class LocalizationRequiredAttribute : Attribute
  343. {
  344. public LocalizationRequiredAttribute() : this(true) { }
  345. public LocalizationRequiredAttribute(bool required)
  346. {
  347. Required = required;
  348. }
  349. public bool Required { get; }
  350. }
  351. /// <summary>
  352. /// Indicates that the value of the marked type (or its derivatives)
  353. /// cannot be compared using '==' or '!=' operators and <c>Equals()</c>
  354. /// should be used instead. However, using '==' or '!=' for comparison
  355. /// with <c>null</c> is always permitted.
  356. /// </summary>
  357. /// <example><code>
  358. /// [CannotApplyEqualityOperator]
  359. /// class NoEquality { }
  360. ///
  361. /// class UsesNoEquality {
  362. /// void Test() {
  363. /// var ca1 = new NoEquality();
  364. /// var ca2 = new NoEquality();
  365. /// if (ca1 != null) { // OK
  366. /// bool condition = ca1 == ca2; // Warning
  367. /// }
  368. /// }
  369. /// }
  370. /// </code></example>
  371. [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)]
  372. public sealed class CannotApplyEqualityOperatorAttribute : Attribute { }
  373. /// <summary>
  374. /// When applied to a target attribute, specifies a requirement for any type marked
  375. /// with the target attribute to implement or inherit specific type or types.
  376. /// </summary>
  377. /// <example><code>
  378. /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement
  379. /// class ComponentAttribute : Attribute { }
  380. ///
  381. /// [Component] // ComponentAttribute requires implementing IComponent interface
  382. /// class MyComponent : IComponent { }
  383. /// </code></example>
  384. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  385. [BaseTypeRequired(typeof(Attribute))]
  386. public sealed class BaseTypeRequiredAttribute : Attribute
  387. {
  388. public BaseTypeRequiredAttribute([NotNull] Type baseType)
  389. {
  390. BaseType = baseType;
  391. }
  392. [NotNull] public Type BaseType { get; }
  393. }
  394. /// <summary>
  395. /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library),
  396. /// so this symbol will not be reported as unused (as well as by other usage inspections).
  397. /// </summary>
  398. [AttributeUsage(AttributeTargets.All)]
  399. public sealed class UsedImplicitlyAttribute : Attribute
  400. {
  401. public UsedImplicitlyAttribute()
  402. : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { }
  403. public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags)
  404. : this(useKindFlags, ImplicitUseTargetFlags.Default) { }
  405. public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags)
  406. : this(ImplicitUseKindFlags.Default, targetFlags) { }
  407. public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
  408. {
  409. UseKindFlags = useKindFlags;
  410. TargetFlags = targetFlags;
  411. }
  412. public ImplicitUseKindFlags UseKindFlags { get; }
  413. public ImplicitUseTargetFlags TargetFlags { get; }
  414. }
  415. /// <summary>
  416. /// Can be applied to attributes, type parameters, and parameters of a type assignable from <see cref="System.Type"/> .
  417. /// When applied to an attribute, the decorated attribute behaves the same as <see cref="UsedImplicitlyAttribute"/>.
  418. /// When applied to a type parameter or to a parameter of type <see cref="System.Type"/>, indicates that the corresponding type
  419. /// is used implicitly.
  420. /// </summary>
  421. [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter | AttributeTargets.Parameter)]
  422. public sealed class MeansImplicitUseAttribute : Attribute
  423. {
  424. public MeansImplicitUseAttribute()
  425. : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { }
  426. public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags)
  427. : this(useKindFlags, ImplicitUseTargetFlags.Default) { }
  428. public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags)
  429. : this(ImplicitUseKindFlags.Default, targetFlags) { }
  430. public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
  431. {
  432. UseKindFlags = useKindFlags;
  433. TargetFlags = targetFlags;
  434. }
  435. [UsedImplicitly] public ImplicitUseKindFlags UseKindFlags { get; }
  436. [UsedImplicitly] public ImplicitUseTargetFlags TargetFlags { get; }
  437. }
  438. /// <summary>
  439. /// Specify the details of implicitly used symbol when it is marked
  440. /// with <see cref="MeansImplicitUseAttribute"/> or <see cref="UsedImplicitlyAttribute"/>.
  441. /// </summary>
  442. [Flags]
  443. public enum ImplicitUseKindFlags
  444. {
  445. Default = Access | Assign | InstantiatedWithFixedConstructorSignature,
  446. /// <summary>Only entity marked with attribute considered used.</summary>
  447. Access = 1,
  448. /// <summary>Indicates implicit assignment to a member.</summary>
  449. Assign = 2,
  450. /// <summary>
  451. /// Indicates implicit instantiation of a type with fixed constructor signature.
  452. /// That means any unused constructor parameters won't be reported as such.
  453. /// </summary>
  454. InstantiatedWithFixedConstructorSignature = 4,
  455. /// <summary>Indicates implicit instantiation of a type.</summary>
  456. InstantiatedNoFixedConstructorSignature = 8,
  457. }
  458. /// <summary>
  459. /// Specify what is considered to be used implicitly when marked
  460. /// with <see cref="MeansImplicitUseAttribute"/> or <see cref="UsedImplicitlyAttribute"/>.
  461. /// </summary>
  462. [Flags]
  463. public enum ImplicitUseTargetFlags
  464. {
  465. Default = Itself,
  466. Itself = 1,
  467. /// <summary>Members of entity marked with attribute are considered used.</summary>
  468. Members = 2,
  469. /// <summary> Inherited entities are considered used. </summary>
  470. WithInheritors = 4,
  471. /// <summary>Entity marked with attribute and all its members considered used.</summary>
  472. WithMembers = Itself | Members
  473. }
  474. /// <summary>
  475. /// This attribute is intended to mark publicly available API
  476. /// which should not be removed and so is treated as used.
  477. /// </summary>
  478. [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)]
  479. [AttributeUsage(AttributeTargets.All, Inherited = false)]
  480. public sealed class PublicAPIAttribute : Attribute
  481. {
  482. public PublicAPIAttribute() { }
  483. public PublicAPIAttribute([NotNull] string comment)
  484. {
  485. Comment = comment;
  486. }
  487. [CanBeNull] public string Comment { get; }
  488. }
  489. /// <summary>
  490. /// Tells code analysis engine if the parameter is completely handled when the invoked method is on stack.
  491. /// If the parameter is a delegate, indicates that delegate is executed while the method is executed.
  492. /// If the parameter is an enumerable, indicates that it is enumerated while the method is executed.
  493. /// </summary>
  494. [AttributeUsage(AttributeTargets.Parameter)]
  495. public sealed class InstantHandleAttribute : Attribute { }
  496. /// <summary>
  497. /// Indicates that a method does not make any observable state changes.
  498. /// The same as <c>System.Diagnostics.Contracts.PureAttribute</c>.
  499. /// </summary>
  500. /// <example><code>
  501. /// [Pure] int Multiply(int x, int y) => x * y;
  502. ///
  503. /// void M() {
  504. /// Multiply(123, 42); // Warning: Return value of pure method is not used
  505. /// }
  506. /// </code></example>
  507. [AttributeUsage(AttributeTargets.Method)]
  508. public sealed class PureAttribute : Attribute { }
  509. /// <summary>
  510. /// Indicates that the return value of the method invocation must be used.
  511. /// </summary>
  512. /// <remarks>
  513. /// Methods decorated with this attribute (in contrast to pure methods) might change state,
  514. /// but make no sense without using their return value. <br/>
  515. /// Similarly to <see cref="PureAttribute"/>, this attribute
  516. /// will help detecting usages of the method when the return value in not used.
  517. /// Additionally, you can optionally specify a custom message, which will be used when showing warnings, e.g.
  518. /// <code>[MustUseReturnValue("Use the return value to...")]</code>.
  519. /// </remarks>
  520. [AttributeUsage(AttributeTargets.Method)]
  521. public sealed class MustUseReturnValueAttribute : Attribute
  522. {
  523. public MustUseReturnValueAttribute() { }
  524. public MustUseReturnValueAttribute([NotNull] string justification)
  525. {
  526. Justification = justification;
  527. }
  528. [CanBeNull] public string Justification { get; }
  529. }
  530. /// <summary>
  531. /// Indicates the type member or parameter of some type, that should be used instead of all other ways
  532. /// to get the value of that type. This annotation is useful when you have some "context" value evaluated
  533. /// and stored somewhere, meaning that all other ways to get this value must be consolidated with existing one.
  534. /// </summary>
  535. /// <example><code>
  536. /// class Foo {
  537. /// [ProvidesContext] IBarService _barService = ...;
  538. ///
  539. /// void ProcessNode(INode node) {
  540. /// DoSomething(node, node.GetGlobalServices().Bar);
  541. /// // ^ Warning: use value of '_barService' field
  542. /// }
  543. /// }
  544. /// </code></example>
  545. [AttributeUsage(
  546. AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Method |
  547. AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.GenericParameter)]
  548. public sealed class ProvidesContextAttribute : Attribute { }
  549. /// <summary>
  550. /// Indicates that a parameter is a path to a file or a folder within a web project.
  551. /// Path can be relative or absolute, starting from web root (~).
  552. /// </summary>
  553. [AttributeUsage(AttributeTargets.Parameter)]
  554. public sealed class PathReferenceAttribute : Attribute
  555. {
  556. public PathReferenceAttribute() { }
  557. public PathReferenceAttribute([NotNull, PathReference] string basePath)
  558. {
  559. BasePath = basePath;
  560. }
  561. [CanBeNull] public string BasePath { get; }
  562. }
  563. /// <summary>
  564. /// An extension method marked with this attribute is processed by code completion
  565. /// as a 'Source Template'. When the extension method is completed over some expression, its source code
  566. /// is automatically expanded like a template at call site.
  567. /// </summary>
  568. /// <remarks>
  569. /// Template method body can contain valid source code and/or special comments starting with '$'.
  570. /// Text inside these comments is added as source code when the template is applied. Template parameters
  571. /// can be used either as additional method parameters or as identifiers wrapped in two '$' signs.
  572. /// Use the <see cref="MacroAttribute"/> attribute to specify macros for parameters.
  573. /// </remarks>
  574. /// <example>
  575. /// In this example, the 'forEach' method is a source template available over all values
  576. /// of enumerable types, producing ordinary C# 'foreach' statement and placing caret inside block:
  577. /// <code>
  578. /// [SourceTemplate]
  579. /// public static void forEach&lt;T&gt;(this IEnumerable&lt;T&gt; xs) {
  580. /// foreach (var x in xs) {
  581. /// //$ $END$
  582. /// }
  583. /// }
  584. /// </code>
  585. /// </example>
  586. [AttributeUsage(AttributeTargets.Method)]
  587. public sealed class SourceTemplateAttribute : Attribute { }
  588. /// <summary>
  589. /// Allows specifying a macro for a parameter of a <see cref="SourceTemplateAttribute">source template</see>.
  590. /// </summary>
  591. /// <remarks>
  592. /// You can apply the attribute on the whole method or on any of its additional parameters. The macro expression
  593. /// is defined in the <see cref="MacroAttribute.Expression"/> property. When applied on a method, the target
  594. /// template parameter is defined in the <see cref="MacroAttribute.Target"/> property. To apply the macro silently
  595. /// for the parameter, set the <see cref="MacroAttribute.Editable"/> property value = -1.
  596. /// </remarks>
  597. /// <example>
  598. /// Applying the attribute on a source template method:
  599. /// <code>
  600. /// [SourceTemplate, Macro(Target = "item", Expression = "suggestVariableName()")]
  601. /// public static void forEach&lt;T&gt;(this IEnumerable&lt;T&gt; collection) {
  602. /// foreach (var item in collection) {
  603. /// //$ $END$
  604. /// }
  605. /// }
  606. /// </code>
  607. /// Applying the attribute on a template method parameter:
  608. /// <code>
  609. /// [SourceTemplate]
  610. /// public static void something(this Entity x, [Macro(Expression = "guid()", Editable = -1)] string newguid) {
  611. /// /*$ var $x$Id = "$newguid$" + x.ToString();
  612. /// x.DoSomething($x$Id); */
  613. /// }
  614. /// </code>
  615. /// </example>
  616. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = true)]
  617. public sealed class MacroAttribute : Attribute
  618. {
  619. /// <summary>
  620. /// Allows specifying a macro that will be executed for a <see cref="SourceTemplateAttribute">source template</see>
  621. /// parameter when the template is expanded.
  622. /// </summary>
  623. [CanBeNull] public string Expression { get; set; }
  624. /// <summary>
  625. /// Allows specifying which occurrence of the target parameter becomes editable when the template is deployed.
  626. /// </summary>
  627. /// <remarks>
  628. /// If the target parameter is used several times in the template, only one occurrence becomes editable;
  629. /// other occurrences are changed synchronously. To specify the zero-based index of the editable occurrence,
  630. /// use values >= 0. To make the parameter non-editable when the template is expanded, use -1.
  631. /// </remarks>
  632. public int Editable { get; set; }
  633. /// <summary>
  634. /// Identifies the target parameter of a <see cref="SourceTemplateAttribute">source template</see> if the
  635. /// <see cref="MacroAttribute"/> is applied on a template method.
  636. /// </summary>
  637. [CanBeNull] public string Target { get; set; }
  638. }
  639. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
  640. public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute
  641. {
  642. public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format)
  643. {
  644. Format = format;
  645. }
  646. [NotNull] public string Format { get; }
  647. }
  648. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
  649. public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute
  650. {
  651. public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format)
  652. {
  653. Format = format;
  654. }
  655. [NotNull] public string Format { get; }
  656. }
  657. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
  658. public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute
  659. {
  660. public AspMvcAreaViewLocationFormatAttribute([NotNull] string format)
  661. {
  662. Format = format;
  663. }
  664. [NotNull] public string Format { get; }
  665. }
  666. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
  667. public sealed class AspMvcMasterLocationFormatAttribute : Attribute
  668. {
  669. public AspMvcMasterLocationFormatAttribute([NotNull] string format)
  670. {
  671. Format = format;
  672. }
  673. [NotNull] public string Format { get; }
  674. }
  675. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
  676. public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute
  677. {
  678. public AspMvcPartialViewLocationFormatAttribute([NotNull] string format)
  679. {
  680. Format = format;
  681. }
  682. [NotNull] public string Format { get; }
  683. }
  684. [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
  685. public sealed class AspMvcViewLocationFormatAttribute : Attribute
  686. {
  687. public AspMvcViewLocationFormatAttribute([NotNull] string format)
  688. {
  689. Format = format;
  690. }
  691. [NotNull] public string Format { get; }
  692. }
  693. /// <summary>
  694. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter
  695. /// is an MVC action. If applied to a method, the MVC action name is calculated
  696. /// implicitly from the context. Use this attribute for custom wrappers similar to
  697. /// <c>System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String)</c>.
  698. /// </summary>
  699. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)]
  700. public sealed class AspMvcActionAttribute : Attribute
  701. {
  702. public AspMvcActionAttribute() { }
  703. public AspMvcActionAttribute([NotNull] string anonymousProperty)
  704. {
  705. AnonymousProperty = anonymousProperty;
  706. }
  707. [CanBeNull] public string AnonymousProperty { get; }
  708. }
  709. /// <summary>
  710. /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC area.
  711. /// Use this attribute for custom wrappers similar to
  712. /// <c>System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String)</c>.
  713. /// </summary>
  714. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  715. public sealed class AspMvcAreaAttribute : Attribute
  716. {
  717. public AspMvcAreaAttribute() { }
  718. public AspMvcAreaAttribute([NotNull] string anonymousProperty)
  719. {
  720. AnonymousProperty = anonymousProperty;
  721. }
  722. [CanBeNull] public string AnonymousProperty { get; }
  723. }
  724. /// <summary>
  725. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is
  726. /// an MVC controller. If applied to a method, the MVC controller name is calculated
  727. /// implicitly from the context. Use this attribute for custom wrappers similar to
  728. /// <c>System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String)</c>.
  729. /// </summary>
  730. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)]
  731. public sealed class AspMvcControllerAttribute : Attribute
  732. {
  733. public AspMvcControllerAttribute() { }
  734. public AspMvcControllerAttribute([NotNull] string anonymousProperty)
  735. {
  736. AnonymousProperty = anonymousProperty;
  737. }
  738. [CanBeNull] public string AnonymousProperty { get; }
  739. }
  740. /// <summary>
  741. /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC Master. Use this attribute
  742. /// for custom wrappers similar to <c>System.Web.Mvc.Controller.View(String, String)</c>.
  743. /// </summary>
  744. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  745. public sealed class AspMvcMasterAttribute : Attribute { }
  746. /// <summary>
  747. /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC model type. Use this attribute
  748. /// for custom wrappers similar to <c>System.Web.Mvc.Controller.View(String, Object)</c>.
  749. /// </summary>
  750. [AttributeUsage(AttributeTargets.Parameter)]
  751. public sealed class AspMvcModelTypeAttribute : Attribute { }
  752. /// <summary>
  753. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is an MVC
  754. /// partial view. If applied to a method, the MVC partial view name is calculated implicitly
  755. /// from the context. Use this attribute for custom wrappers similar to
  756. /// <c>System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String)</c>.
  757. /// </summary>
  758. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)]
  759. public sealed class AspMvcPartialViewAttribute : Attribute { }
  760. /// <summary>
  761. /// ASP.NET MVC attribute. Allows disabling inspections for MVC views within a class or a method.
  762. /// </summary>
  763. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
  764. public sealed class AspMvcSuppressViewErrorAttribute : Attribute { }
  765. /// <summary>
  766. /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template.
  767. /// Use this attribute for custom wrappers similar to
  768. /// <c>System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String)</c>.
  769. /// </summary>
  770. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  771. public sealed class AspMvcDisplayTemplateAttribute : Attribute { }
  772. /// <summary>
  773. /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC editor template.
  774. /// Use this attribute for custom wrappers similar to
  775. /// <c>System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String)</c>.
  776. /// </summary>
  777. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  778. public sealed class AspMvcEditorTemplateAttribute : Attribute { }
  779. /// <summary>
  780. /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC template.
  781. /// Use this attribute for custom wrappers similar to
  782. /// <c>System.ComponentModel.DataAnnotations.UIHintAttribute(System.String)</c>.
  783. /// </summary>
  784. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  785. public sealed class AspMvcTemplateAttribute : Attribute { }
  786. /// <summary>
  787. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter
  788. /// is an MVC view component. If applied to a method, the MVC view name is calculated implicitly
  789. /// from the context. Use this attribute for custom wrappers similar to
  790. /// <c>System.Web.Mvc.Controller.View(Object)</c>.
  791. /// </summary>
  792. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)]
  793. public sealed class AspMvcViewAttribute : Attribute { }
  794. /// <summary>
  795. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter
  796. /// is an MVC view component name.
  797. /// </summary>
  798. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  799. public sealed class AspMvcViewComponentAttribute : Attribute { }
  800. /// <summary>
  801. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter
  802. /// is an MVC view component view. If applied to a method, the MVC view component view name is default.
  803. /// </summary>
  804. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)]
  805. public sealed class AspMvcViewComponentViewAttribute : Attribute { }
  806. /// <summary>
  807. /// ASP.NET MVC attribute. When applied to a parameter of an attribute,
  808. /// indicates that this parameter is an MVC action name.
  809. /// </summary>
  810. /// <example><code>
  811. /// [ActionName("Foo")]
  812. /// public ActionResult Login(string returnUrl) {
  813. /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK
  814. /// return RedirectToAction("Bar"); // Error: Cannot resolve action
  815. /// }
  816. /// </code></example>
  817. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
  818. public sealed class AspMvcActionSelectorAttribute : Attribute { }
  819. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)]
  820. public sealed class HtmlElementAttributesAttribute : Attribute
  821. {
  822. public HtmlElementAttributesAttribute() { }
  823. public HtmlElementAttributesAttribute([NotNull] string name)
  824. {
  825. Name = name;
  826. }
  827. [CanBeNull] public string Name { get; }
  828. }
  829. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  830. public sealed class HtmlAttributeValueAttribute : Attribute
  831. {
  832. public HtmlAttributeValueAttribute([NotNull] string name)
  833. {
  834. Name = name;
  835. }
  836. [NotNull] public string Name { get; }
  837. }
  838. /// <summary>
  839. /// Razor attribute. Indicates that the marked parameter or method is a Razor section.
  840. /// Use this attribute for custom wrappers similar to
  841. /// <c>System.Web.WebPages.WebPageBase.RenderSection(String)</c>.
  842. /// </summary>
  843. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
  844. public sealed class RazorSectionAttribute : Attribute { }
  845. /// <summary>
  846. /// Indicates how method, constructor invocation, or property access
  847. /// over collection type affects the contents of the collection.
  848. /// Use <see cref="CollectionAccessType"/> to specify the access type.
  849. /// </summary>
  850. /// <remarks>
  851. /// Using this attribute only makes sense if all collection methods are marked with this attribute.
  852. /// </remarks>
  853. /// <example><code>
  854. /// public class MyStringCollection : List&lt;string&gt;
  855. /// {
  856. /// [CollectionAccess(CollectionAccessType.Read)]
  857. /// public string GetFirstString()
  858. /// {
  859. /// return this.ElementAt(0);
  860. /// }
  861. /// }
  862. /// class Test
  863. /// {
  864. /// public void Foo()
  865. /// {
  866. /// // Warning: Contents of the collection is never updated
  867. /// var col = new MyStringCollection();
  868. /// string x = col.GetFirstString();
  869. /// }
  870. /// }
  871. /// </code></example>
  872. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)]
  873. public sealed class CollectionAccessAttribute : Attribute
  874. {
  875. public CollectionAccessAttribute(CollectionAccessType collectionAccessType)
  876. {
  877. CollectionAccessType = collectionAccessType;
  878. }
  879. public CollectionAccessType CollectionAccessType { get; }
  880. }
  881. /// <summary>
  882. /// Provides a value for the <see cref="CollectionAccessAttribute"/> to define
  883. /// how the collection method invocation affects the contents of the collection.
  884. /// </summary>
  885. [Flags]
  886. public enum CollectionAccessType
  887. {
  888. /// <summary>Method does not use or modify content of the collection.</summary>
  889. None = 0,
  890. /// <summary>Method only reads content of the collection but does not modify it.</summary>
  891. Read = 1,
  892. /// <summary>Method can change content of the collection but does not add new elements.</summary>
  893. ModifyExistingContent = 2,
  894. /// <summary>Method can add new elements to the collection.</summary>
  895. UpdatedContent = ModifyExistingContent | 4
  896. }
  897. /// <summary>
  898. /// Indicates that the marked method is assertion method, i.e. it halts the control flow if
  899. /// one of the conditions is satisfied. To set the condition, mark one of the parameters with
  900. /// <see cref="AssertionConditionAttribute"/> attribute.
  901. /// </summary>
  902. [AttributeUsage(AttributeTargets.Method)]
  903. public sealed class AssertionMethodAttribute : Attribute { }
  904. /// <summary>
  905. /// Indicates the condition parameter of the assertion method. The method itself should be
  906. /// marked by <see cref="AssertionMethodAttribute"/> attribute. The mandatory argument of
  907. /// the attribute is the assertion type.
  908. /// </summary>
  909. [AttributeUsage(AttributeTargets.Parameter)]
  910. public sealed class AssertionConditionAttribute : Attribute
  911. {
  912. public AssertionConditionAttribute(AssertionConditionType conditionType)
  913. {
  914. ConditionType = conditionType;
  915. }
  916. public AssertionConditionType ConditionType { get; }
  917. }
  918. /// <summary>
  919. /// Specifies assertion type. If the assertion method argument satisfies the condition,
  920. /// then the execution continues. Otherwise, execution is assumed to be halted.
  921. /// </summary>
  922. public enum AssertionConditionType
  923. {
  924. /// <summary>Marked parameter should be evaluated to true.</summary>
  925. IS_TRUE = 0,
  926. /// <summary>Marked parameter should be evaluated to false.</summary>
  927. IS_FALSE = 1,
  928. /// <summary>Marked parameter should be evaluated to null value.</summary>
  929. IS_NULL = 2,
  930. /// <summary>Marked parameter should be evaluated to not null value.</summary>
  931. IS_NOT_NULL = 3,
  932. }
  933. /// <summary>
  934. /// Indicates that the marked method unconditionally terminates control flow execution.
  935. /// For example, it could unconditionally throw exception.
  936. /// </summary>
  937. [Obsolete("Use [ContractAnnotation('=> halt')] instead")]
  938. [AttributeUsage(AttributeTargets.Method)]
  939. public sealed class TerminatesProgramAttribute : Attribute { }
  940. /// <summary>
  941. /// Indicates that method is pure LINQ method, with postponed enumeration (like Enumerable.Select,
  942. /// .Where). This annotation allows inference of [InstantHandle] annotation for parameters
  943. /// of delegate type by analyzing LINQ method chains.
  944. /// </summary>
  945. [AttributeUsage(AttributeTargets.Method)]
  946. public sealed class LinqTunnelAttribute : Attribute { }
  947. /// <summary>
  948. /// Indicates that IEnumerable passed as a parameter is not enumerated.
  949. /// Use this annotation to suppress the 'Possible multiple enumeration of IEnumerable' inspection.
  950. /// </summary>
  951. /// <example><code>
  952. /// static void ThrowIfNull&lt;T&gt;([NoEnumeration] T v, string n) where T : class
  953. /// {
  954. /// // custom check for null but no enumeration
  955. /// }
  956. ///
  957. /// void Foo(IEnumerable&lt;string&gt; values)
  958. /// {
  959. /// ThrowIfNull(values, nameof(values));
  960. /// var x = values.ToList(); // No warnings about multiple enumeration
  961. /// }
  962. /// </code></example>
  963. [AttributeUsage(AttributeTargets.Parameter)]
  964. public sealed class NoEnumerationAttribute : Attribute { }
  965. /// <summary>
  966. /// Indicates that the marked parameter is a regular expression pattern.
  967. /// </summary>
  968. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  969. public sealed class RegexPatternAttribute : Attribute { }
  970. /// <summary>
  971. /// Prevents the Member Reordering feature from tossing members of the marked class.
  972. /// </summary>
  973. /// <remarks>
  974. /// The attribute must be mentioned in your member reordering patterns.
  975. /// </remarks>
  976. [AttributeUsage(
  977. AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum)]
  978. public sealed class NoReorderAttribute : Attribute { }
  979. /// <summary>
  980. /// XAML attribute. Indicates the type that has <c>ItemsSource</c> property and should be treated
  981. /// as <c>ItemsControl</c>-derived type, to enable inner items <c>DataContext</c> type resolve.
  982. /// </summary>
  983. [AttributeUsage(AttributeTargets.Class)]
  984. public sealed class XamlItemsControlAttribute : Attribute { }
  985. /// <summary>
  986. /// XAML attribute. Indicates the property of some <c>BindingBase</c>-derived type, that
  987. /// is used to bind some item of <c>ItemsControl</c>-derived type. This annotation will
  988. /// enable the <c>DataContext</c> type resolve for XAML bindings for such properties.
  989. /// </summary>
  990. /// <remarks>
  991. /// Property should have the tree ancestor of the <c>ItemsControl</c> type or
  992. /// marked with the <see cref="XamlItemsControlAttribute"/> attribute.
  993. /// </remarks>
  994. [AttributeUsage(AttributeTargets.Property)]
  995. public sealed class XamlItemBindingOfItemsControlAttribute : Attribute { }
  996. /// <summary>
  997. /// XAML attribute. Indicates the property of some <c>Style</c>-derived type, that
  998. /// is used to style items of <c>ItemsControl</c>-derived type. This annotation will
  999. /// enable the <c>DataContext</c> type resolve for XAML bindings for such properties.
  1000. /// </summary>
  1001. /// <remarks>
  1002. /// Property should have the tree ancestor of the <c>ItemsControl</c> type or
  1003. /// marked with the <see cref="XamlItemsControlAttribute"/> attribute.
  1004. /// </remarks>
  1005. [AttributeUsage(AttributeTargets.Property)]
  1006. public sealed class XamlItemStyleOfItemsControlAttribute : Attribute { }
  1007. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  1008. public sealed class AspChildControlTypeAttribute : Attribute
  1009. {
  1010. public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType)
  1011. {
  1012. TagName = tagName;
  1013. ControlType = controlType;
  1014. }
  1015. [NotNull] public string TagName { get; }
  1016. [NotNull] public Type ControlType { get; }
  1017. }
  1018. [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
  1019. public sealed class AspDataFieldAttribute : Attribute { }
  1020. [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
  1021. public sealed class AspDataFieldsAttribute : Attribute { }
  1022. [AttributeUsage(AttributeTargets.Property)]
  1023. public sealed class AspMethodPropertyAttribute : Attribute { }
  1024. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  1025. public sealed class AspRequiredAttributeAttribute : Attribute
  1026. {
  1027. public AspRequiredAttributeAttribute([NotNull] string attribute)
  1028. {
  1029. Attribute = attribute;
  1030. }
  1031. [NotNull] public string Attribute { get; }
  1032. }
  1033. [AttributeUsage(AttributeTargets.Property)]
  1034. public sealed class AspTypePropertyAttribute : Attribute
  1035. {
  1036. public bool CreateConstructorReferences { get; }
  1037. public AspTypePropertyAttribute(bool createConstructorReferences)
  1038. {
  1039. CreateConstructorReferences = createConstructorReferences;
  1040. }
  1041. }
  1042. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  1043. public sealed class RazorImportNamespaceAttribute : Attribute
  1044. {
  1045. public RazorImportNamespaceAttribute([NotNull] string name)
  1046. {
  1047. Name = name;
  1048. }
  1049. [NotNull] public string Name { get; }
  1050. }
  1051. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  1052. public sealed class RazorInjectionAttribute : Attribute
  1053. {
  1054. public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName)
  1055. {
  1056. Type = type;
  1057. FieldName = fieldName;
  1058. }
  1059. [NotNull] public string Type { get; }
  1060. [NotNull] public string FieldName { get; }
  1061. }
  1062. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  1063. public sealed class RazorDirectiveAttribute : Attribute
  1064. {
  1065. public RazorDirectiveAttribute([NotNull] string directive)
  1066. {
  1067. Directive = directive;
  1068. }
  1069. [NotNull] public string Directive { get; }
  1070. }
  1071. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  1072. public sealed class RazorPageBaseTypeAttribute : Attribute
  1073. {
  1074. public RazorPageBaseTypeAttribute([NotNull] string baseType)
  1075. {
  1076. BaseType = baseType;
  1077. }
  1078. public RazorPageBaseTypeAttribute([NotNull] string baseType, string pageName)
  1079. {
  1080. BaseType = baseType;
  1081. PageName = pageName;
  1082. }
  1083. [NotNull] public string BaseType { get; }
  1084. [CanBeNull] public string PageName { get; }
  1085. }
  1086. [AttributeUsage(AttributeTargets.Method)]
  1087. public sealed class RazorHelperCommonAttribute : Attribute { }
  1088. [AttributeUsage(AttributeTargets.Property)]
  1089. public sealed class RazorLayoutAttribute : Attribute { }
  1090. [AttributeUsage(AttributeTargets.Method)]
  1091. public sealed class RazorWriteLiteralMethodAttribute : Attribute { }
  1092. [AttributeUsage(AttributeTargets.Method)]
  1093. public sealed class RazorWriteMethodAttribute : Attribute { }
  1094. [AttributeUsage(AttributeTargets.Parameter)]
  1095. public sealed class RazorWriteMethodParameterAttribute : Attribute { }
  1096. }