Jetbrains.Annotations.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. 
  2. #if !UNITY_5 && !UNITY_5_3_OR_NEWER && UNITY_EDITOR
  3. using System;
  4. using System.Diagnostics;
  5. #pragma warning disable 1591
  6. // ReSharper disable UnusedMember.Global
  7. // ReSharper disable MemberCanBePrivate.Global
  8. // ReSharper disable UnusedAutoPropertyAccessor.Global
  9. // ReSharper disable IntroduceOptionalParameters.Global
  10. // ReSharper disable MemberCanBeProtected.Global
  11. // ReSharper disable InconsistentNaming
  12. namespace JetBrains.Annotations
  13. {
  14. /// <summary>
  15. /// Indicates that the value of the marked element could be <c>null</c> sometimes,
  16. /// so the check for <c>null</c> is necessary before its usage
  17. /// </summary>
  18. /// <example><code>
  19. /// [CanBeNull] public object Test() { return null; }
  20. /// public void UseTest() {
  21. /// var p = Test();
  22. /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
  23. /// }
  24. /// </code></example>
  25. [AttributeUsage(
  26. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  27. AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event)]
  28. [Conditional("JETBRAINS_ANNOTATIONS")]
  29. public sealed class CanBeNullAttribute : Attribute { }
  30. /// <summary>
  31. /// Indicates that the value of the marked element could never be <c>null</c>
  32. /// </summary>
  33. /// <example><code>
  34. /// [NotNull] public object Foo() {
  35. /// return null; // Warning: Possible 'null' assignment
  36. /// }
  37. /// </code></example>
  38. [AttributeUsage(
  39. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  40. AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event)]
  41. [Conditional("JETBRAINS_ANNOTATIONS")]
  42. public sealed class NotNullAttribute : Attribute { }
  43. /// <summary>
  44. /// Indicates that collection or enumerable value does not contain null elements
  45. /// </summary>
  46. [AttributeUsage(
  47. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  48. AttributeTargets.Delegate | AttributeTargets.Field)]
  49. [Conditional("JETBRAINS_ANNOTATIONS")]
  50. public sealed class ItemNotNullAttribute : Attribute { }
  51. /// <summary>
  52. /// Indicates that collection or enumerable value can contain null elements
  53. /// </summary>
  54. [AttributeUsage(
  55. AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
  56. AttributeTargets.Delegate | AttributeTargets.Field)]
  57. [Conditional("JETBRAINS_ANNOTATIONS")]
  58. public sealed class ItemCanBeNullAttribute : Attribute { }
  59. /// <summary>
  60. /// Indicates that the marked method builds string by format pattern and (optional) arguments.
  61. /// Parameter, which contains format string, should be given in constructor. The format string
  62. /// should be in <see cref="string.Format(IFormatProvider,string,object[])"/>-like form
  63. /// </summary>
  64. /// <example><code>
  65. /// [StringFormatMethod("message")]
  66. /// public void ShowError(string message, params object[] args) { /* do something */ }
  67. /// public void Foo() {
  68. /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string
  69. /// }
  70. /// </code></example>
  71. [AttributeUsage(
  72. AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Delegate)]
  73. [Conditional("JETBRAINS_ANNOTATIONS")]
  74. public sealed class StringFormatMethodAttribute : Attribute
  75. {
  76. /// <param name="formatParameterName">
  77. /// Specifies which parameter of an annotated method should be treated as format-string
  78. /// </param>
  79. public StringFormatMethodAttribute(string formatParameterName)
  80. {
  81. FormatParameterName = formatParameterName;
  82. }
  83. public string FormatParameterName { get; private set; }
  84. }
  85. /// <summary>
  86. /// For a parameter that is expected to be one of the limited set of values.
  87. /// Specify fields of which type should be used as values for this parameter.
  88. /// </summary>
  89. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)]
  90. [Conditional("JETBRAINS_ANNOTATIONS")]
  91. public sealed class ValueProviderAttribute : Attribute
  92. {
  93. public ValueProviderAttribute(string name)
  94. {
  95. Name = name;
  96. }
  97. [NotNull]
  98. public string Name { get; private set; }
  99. }
  100. /// <summary>
  101. /// Indicates that the function argument should be string literal and match one
  102. /// of the parameters of the caller function. For example, ReSharper annotates
  103. /// the parameter of <see cref="System.ArgumentNullException"/>
  104. /// </summary>
  105. /// <example><code>
  106. /// public void Foo(string param) {
  107. /// if (param == null)
  108. /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
  109. /// }
  110. /// </code></example>
  111. [AttributeUsage(AttributeTargets.Parameter)]
  112. [Conditional("JETBRAINS_ANNOTATIONS")]
  113. public sealed class InvokerParameterNameAttribute : Attribute { }
  114. /// <summary>
  115. /// Indicates that the method is contained in a type that implements
  116. /// <c>System.ComponentModel.INotifyPropertyChanged</c> interface and this method
  117. /// is used to notify that some property value changed
  118. /// </summary>
  119. /// <remarks>
  120. /// The method should be non-static and conform to one of the supported signatures:
  121. /// <list>
  122. /// <item><c>NotifyChanged(string)</c></item>
  123. /// <item><c>NotifyChanged(params string[])</c></item>
  124. /// <item><c>NotifyChanged{T}(Expression{Func{T}})</c></item>
  125. /// <item><c>NotifyChanged{T,U}(Expression{Func{T,U}})</c></item>
  126. /// <item><c>SetProperty{T}(ref T, T, string)</c></item>
  127. /// </list>
  128. /// </remarks>
  129. /// <example><code>
  130. /// public class Foo : INotifyPropertyChanged {
  131. /// public event PropertyChangedEventHandler PropertyChanged;
  132. /// [NotifyPropertyChangedInvocator]
  133. /// protected virtual void NotifyChanged(string propertyName) { ... }
  134. ///
  135. /// private string _name;
  136. /// public string Name {
  137. /// get { return _name; }
  138. /// set { _name = value; NotifyChanged("LastName"); /* Warning */ }
  139. /// }
  140. /// }
  141. /// </code>
  142. /// Examples of generated notifications:
  143. /// <list>
  144. /// <item><c>NotifyChanged("Property")</c></item>
  145. /// <item><c>NotifyChanged(() =&gt; Property)</c></item>
  146. /// <item><c>NotifyChanged((VM x) =&gt; x.Property)</c></item>
  147. /// <item><c>SetProperty(ref myField, value, "Property")</c></item>
  148. /// </list>
  149. /// </example>
  150. [AttributeUsage(AttributeTargets.Method)]
  151. [Conditional("JETBRAINS_ANNOTATIONS")]
  152. public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute
  153. {
  154. public NotifyPropertyChangedInvocatorAttribute() { }
  155. public NotifyPropertyChangedInvocatorAttribute(string parameterName)
  156. {
  157. ParameterName = parameterName;
  158. }
  159. public string ParameterName { get; private set; }
  160. }
  161. /// <summary>
  162. /// Describes dependency between method input and output
  163. /// </summary>
  164. /// <syntax>
  165. /// <p>Function Definition Table syntax:</p>
  166. /// <list>
  167. /// <item>FDT ::= FDTRow [;FDTRow]*</item>
  168. /// <item>FDTRow ::= Input =&gt; Output | Output &lt;= Input</item>
  169. /// <item>Input ::= ParameterName: Value [, Input]*</item>
  170. /// <item>Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value}</item>
  171. /// <item>Value ::= true | false | null | notnull | canbenull</item>
  172. /// </list>
  173. /// If method has single input parameter, it's name could be omitted.<br/>
  174. /// Using <c>halt</c> (or <c>void</c>/<c>nothing</c>, which is the same)
  175. /// for method output means that the methos doesn't return normally.<br/>
  176. /// <c>canbenull</c> annotation is only applicable for output parameters.<br/>
  177. /// You can use multiple <c>[ContractAnnotation]</c> for each FDT row,
  178. /// or use single attribute with rows separated by semicolon.<br/>
  179. /// </syntax>
  180. /// <examples><list>
  181. /// <item><code>
  182. /// [ContractAnnotation("=> halt")]
  183. /// public void TerminationMethod()
  184. /// </code></item>
  185. /// <item><code>
  186. /// [ContractAnnotation("halt &lt;= condition: false")]
  187. /// public void Assert(bool condition, string text) // regular assertion method
  188. /// </code></item>
  189. /// <item><code>
  190. /// [ContractAnnotation("s:null => true")]
  191. /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty()
  192. /// </code></item>
  193. /// <item><code>
  194. /// // A method that returns null if the parameter is null,
  195. /// // and not null if the parameter is not null
  196. /// [ContractAnnotation("null => null; notnull => notnull")]
  197. /// public object Transform(object data)
  198. /// </code></item>
  199. /// <item><code>
  200. /// [ContractAnnotation("s:null=>false; =>true,result:notnull; =>false, result:null")]
  201. /// public bool TryParse(string s, out Person result)
  202. /// </code></item>
  203. /// </list></examples>
  204. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
  205. [Conditional("JETBRAINS_ANNOTATIONS")]
  206. public sealed class ContractAnnotationAttribute : Attribute
  207. {
  208. public ContractAnnotationAttribute([NotNull] string contract)
  209. : this(contract, false) { }
  210. public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates)
  211. {
  212. Contract = contract;
  213. ForceFullStates = forceFullStates;
  214. }
  215. public string Contract { get; private set; }
  216. public bool ForceFullStates { get; private set; }
  217. }
  218. /// <summary>
  219. /// Indicates that marked element should be localized or not
  220. /// </summary>
  221. /// <example><code>
  222. /// [LocalizationRequiredAttribute(true)]
  223. /// public class Foo {
  224. /// private string str = "my string"; // Warning: Localizable string
  225. /// }
  226. /// </code></example>
  227. [AttributeUsage(AttributeTargets.All)]
  228. [Conditional("JETBRAINS_ANNOTATIONS")]
  229. public sealed class LocalizationRequiredAttribute : Attribute
  230. {
  231. public LocalizationRequiredAttribute() : this(true) { }
  232. public LocalizationRequiredAttribute(bool required)
  233. {
  234. Required = required;
  235. }
  236. public bool Required { get; private set; }
  237. }
  238. /// <summary>
  239. /// Indicates that the value of the marked type (or its derivatives)
  240. /// cannot be compared using '==' or '!=' operators and <c>Equals()</c>
  241. /// should be used instead. However, using '==' or '!=' for comparison
  242. /// with <c>null</c> is always permitted.
  243. /// </summary>
  244. /// <example><code>
  245. /// [CannotApplyEqualityOperator]
  246. /// class NoEquality { }
  247. /// class UsesNoEquality {
  248. /// public void Test() {
  249. /// var ca1 = new NoEquality();
  250. /// var ca2 = new NoEquality();
  251. /// if (ca1 != null) { // OK
  252. /// bool condition = ca1 == ca2; // Warning
  253. /// }
  254. /// }
  255. /// }
  256. /// </code></example>
  257. [AttributeUsage(
  258. AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)]
  259. [Conditional("JETBRAINS_ANNOTATIONS")]
  260. public sealed class CannotApplyEqualityOperatorAttribute : Attribute { }
  261. /// <summary>
  262. /// When applied to a target attribute, specifies a requirement for any type marked
  263. /// with the target attribute to implement or inherit specific type or types.
  264. /// </summary>
  265. /// <example><code>
  266. /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement
  267. /// public class ComponentAttribute : Attribute { }
  268. /// [Component] // ComponentAttribute requires implementing IComponent interface
  269. /// public class MyComponent : IComponent { }
  270. /// </code></example>
  271. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  272. [BaseTypeRequired(typeof(Attribute))]
  273. [Conditional("JETBRAINS_ANNOTATIONS")]
  274. public sealed class BaseTypeRequiredAttribute : Attribute
  275. {
  276. public BaseTypeRequiredAttribute([NotNull] Type baseType)
  277. {
  278. BaseType = baseType;
  279. }
  280. [NotNull]
  281. public Type BaseType { get; private set; }
  282. }
  283. /// <summary>
  284. /// Indicates that the marked symbol is used implicitly
  285. /// (e.g. via reflection, in external library), so this symbol
  286. /// will not be marked as unused (as well as by other usage inspections)
  287. /// </summary>
  288. [AttributeUsage(AttributeTargets.All)]
  289. [Conditional("JETBRAINS_ANNOTATIONS")]
  290. public sealed class UsedImplicitlyAttribute : Attribute
  291. {
  292. public UsedImplicitlyAttribute()
  293. : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { }
  294. public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags)
  295. : this(useKindFlags, ImplicitUseTargetFlags.Default) { }
  296. public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags)
  297. : this(ImplicitUseKindFlags.Default, targetFlags) { }
  298. public UsedImplicitlyAttribute(
  299. ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
  300. {
  301. UseKindFlags = useKindFlags;
  302. TargetFlags = targetFlags;
  303. }
  304. public ImplicitUseKindFlags UseKindFlags { get; private set; }
  305. public ImplicitUseTargetFlags TargetFlags { get; private set; }
  306. }
  307. /// <summary>
  308. /// Should be used on attributes and causes ReSharper
  309. /// to not mark symbols marked with such attributes as unused
  310. /// (as well as by other usage inspections)
  311. /// </summary>
  312. [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)]
  313. [Conditional("JETBRAINS_ANNOTATIONS")]
  314. public sealed class MeansImplicitUseAttribute : Attribute
  315. {
  316. public MeansImplicitUseAttribute()
  317. : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { }
  318. public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags)
  319. : this(useKindFlags, ImplicitUseTargetFlags.Default) { }
  320. public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags)
  321. : this(ImplicitUseKindFlags.Default, targetFlags) { }
  322. public MeansImplicitUseAttribute(
  323. ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
  324. {
  325. UseKindFlags = useKindFlags;
  326. TargetFlags = targetFlags;
  327. }
  328. [UsedImplicitly]
  329. public ImplicitUseKindFlags UseKindFlags { get; private set; }
  330. [UsedImplicitly]
  331. public ImplicitUseTargetFlags TargetFlags { get; private set; }
  332. }
  333. [Flags]
  334. public enum ImplicitUseKindFlags
  335. {
  336. Default = Access | Assign | InstantiatedWithFixedConstructorSignature,
  337. /// <summary>Only entity marked with attribute considered used</summary>
  338. Access = 1,
  339. /// <summary>Indicates implicit assignment to a member</summary>
  340. Assign = 2,
  341. /// <summary>
  342. /// Indicates implicit instantiation of a type with fixed constructor signature.
  343. /// That means any unused constructor parameters won't be reported as such.
  344. /// </summary>
  345. InstantiatedWithFixedConstructorSignature = 4,
  346. /// <summary>Indicates implicit instantiation of a type</summary>
  347. InstantiatedNoFixedConstructorSignature = 8,
  348. }
  349. /// <summary>
  350. /// Specify what is considered used implicitly when marked
  351. /// with <see cref="MeansImplicitUseAttribute"/> or <see cref="UsedImplicitlyAttribute"/>
  352. /// </summary>
  353. [Flags]
  354. public enum ImplicitUseTargetFlags
  355. {
  356. Default = Itself,
  357. Itself = 1,
  358. /// <summary>Members of entity marked with attribute are considered used</summary>
  359. Members = 2,
  360. /// <summary>Entity marked with attribute and all its members considered used</summary>
  361. WithMembers = Itself | Members
  362. }
  363. /// <summary>
  364. /// This attribute is intended to mark publicly available API
  365. /// which should not be removed and so is treated as used
  366. /// </summary>
  367. [MeansImplicitUse]
  368. [Conditional("JETBRAINS_ANNOTATIONS")]
  369. public sealed class PublicAPIAttribute : Attribute
  370. {
  371. public PublicAPIAttribute() { }
  372. public PublicAPIAttribute([NotNull] string comment)
  373. {
  374. Comment = comment;
  375. }
  376. public string Comment { get; private set; }
  377. }
  378. /// <summary>
  379. /// Tells code analysis engine if the parameter is completely handled
  380. /// when the invoked method is on stack. If the parameter is a delegate,
  381. /// indicates that delegate is executed while the method is executed.
  382. /// If the parameter is an enumerable, indicates that it is enumerated
  383. /// while the method is executed
  384. /// </summary>
  385. [AttributeUsage(AttributeTargets.Parameter)]
  386. [Conditional("JETBRAINS_ANNOTATIONS")]
  387. public sealed class InstantHandleAttribute : Attribute { }
  388. /// <summary>
  389. /// Indicates that a method does not make any observable state changes.
  390. /// The same as <c>System.Diagnostics.Contracts.PureAttribute</c>
  391. /// </summary>
  392. /// <example><code>
  393. /// [Pure] private int Multiply(int x, int y) { return x * y; }
  394. /// public void Foo() {
  395. /// const int a = 2, b = 2;
  396. /// Multiply(a, b); // Waring: Return value of pure method is not used
  397. /// }
  398. /// </code></example>
  399. [AttributeUsage(AttributeTargets.Method)]
  400. [Conditional("JETBRAINS_ANNOTATIONS")]
  401. public sealed class PureAttribute : Attribute { }
  402. /// <summary>
  403. /// Indicates that a parameter is a path to a file or a folder within a web project.
  404. /// Path can be relative or absolute, starting from web root (~)
  405. /// </summary>
  406. [AttributeUsage(AttributeTargets.Parameter)]
  407. [Conditional("JETBRAINS_ANNOTATIONS")]
  408. public class PathReferenceAttribute : Attribute
  409. {
  410. public PathReferenceAttribute() { }
  411. public PathReferenceAttribute([PathReference] string basePath)
  412. {
  413. BasePath = basePath;
  414. }
  415. public string BasePath { get; private set; }
  416. }
  417. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  418. [Conditional("JETBRAINS_ANNOTATIONS")]
  419. public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute
  420. {
  421. public AspMvcAreaMasterLocationFormatAttribute(string format)
  422. {
  423. Format = format;
  424. }
  425. public string Format { get; private set; }
  426. }
  427. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  428. [Conditional("JETBRAINS_ANNOTATIONS")]
  429. public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute
  430. {
  431. public AspMvcAreaPartialViewLocationFormatAttribute(string format)
  432. {
  433. Format = format;
  434. }
  435. public string Format { get; private set; }
  436. }
  437. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  438. [Conditional("JETBRAINS_ANNOTATIONS")]
  439. public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute
  440. {
  441. public AspMvcAreaViewLocationFormatAttribute(string format)
  442. {
  443. Format = format;
  444. }
  445. public string Format { get; private set; }
  446. }
  447. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  448. [Conditional("JETBRAINS_ANNOTATIONS")]
  449. public sealed class AspMvcMasterLocationFormatAttribute : Attribute
  450. {
  451. public AspMvcMasterLocationFormatAttribute(string format)
  452. {
  453. Format = format;
  454. }
  455. public string Format { get; private set; }
  456. }
  457. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  458. [Conditional("JETBRAINS_ANNOTATIONS")]
  459. public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute
  460. {
  461. public AspMvcPartialViewLocationFormatAttribute(string format)
  462. {
  463. Format = format;
  464. }
  465. public string Format { get; private set; }
  466. }
  467. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  468. [Conditional("JETBRAINS_ANNOTATIONS")]
  469. public sealed class AspMvcViewLocationFormatAttribute : Attribute
  470. {
  471. public AspMvcViewLocationFormatAttribute(string format)
  472. {
  473. Format = format;
  474. }
  475. public string Format { get; private set; }
  476. }
  477. /// <summary>
  478. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter
  479. /// is an MVC action. If applied to a method, the MVC action name is calculated
  480. /// implicitly from the context. Use this attribute for custom wrappers similar to
  481. /// <c>System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String)</c>
  482. /// </summary>
  483. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
  484. [Conditional("JETBRAINS_ANNOTATIONS")]
  485. public sealed class AspMvcActionAttribute : Attribute
  486. {
  487. public AspMvcActionAttribute() { }
  488. public AspMvcActionAttribute(string anonymousProperty)
  489. {
  490. AnonymousProperty = anonymousProperty;
  491. }
  492. public string AnonymousProperty { get; private set; }
  493. }
  494. /// <summary>
  495. /// ASP.NET MVC attribute. Indicates that a parameter is an MVC area.
  496. /// Use this attribute for custom wrappers similar to
  497. /// <c>System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String)</c>
  498. /// </summary>
  499. [AttributeUsage(AttributeTargets.Parameter)]
  500. [Conditional("JETBRAINS_ANNOTATIONS")]
  501. public sealed class AspMvcAreaAttribute : PathReferenceAttribute
  502. {
  503. public AspMvcAreaAttribute() { }
  504. public AspMvcAreaAttribute(string anonymousProperty)
  505. {
  506. AnonymousProperty = anonymousProperty;
  507. }
  508. public string AnonymousProperty { get; private set; }
  509. }
  510. /// <summary>
  511. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is
  512. /// an MVC controller. If applied to a method, the MVC controller name is calculated
  513. /// implicitly from the context. Use this attribute for custom wrappers similar to
  514. /// <c>System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String)</c>
  515. /// </summary>
  516. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
  517. [Conditional("JETBRAINS_ANNOTATIONS")]
  518. public sealed class AspMvcControllerAttribute : Attribute
  519. {
  520. public AspMvcControllerAttribute() { }
  521. public AspMvcControllerAttribute(string anonymousProperty)
  522. {
  523. AnonymousProperty = anonymousProperty;
  524. }
  525. public string AnonymousProperty { get; private set; }
  526. }
  527. /// <summary>
  528. /// ASP.NET MVC attribute. Indicates that a parameter is an MVC Master. Use this attribute
  529. /// for custom wrappers similar to <c>System.Web.Mvc.Controller.View(String, String)</c>
  530. /// </summary>
  531. [AttributeUsage(AttributeTargets.Parameter)]
  532. [Conditional("JETBRAINS_ANNOTATIONS")]
  533. public sealed class AspMvcMasterAttribute : Attribute { }
  534. /// <summary>
  535. /// ASP.NET MVC attribute. Indicates that a parameter is an MVC model type. Use this attribute
  536. /// for custom wrappers similar to <c>System.Web.Mvc.Controller.View(String, Object)</c>
  537. /// </summary>
  538. [AttributeUsage(AttributeTargets.Parameter)]
  539. [Conditional("JETBRAINS_ANNOTATIONS")]
  540. public sealed class AspMvcModelTypeAttribute : Attribute { }
  541. /// <summary>
  542. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is an MVC
  543. /// partial view. If applied to a method, the MVC partial view name is calculated implicitly
  544. /// from the context. Use this attribute for custom wrappers similar to
  545. /// <c>System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String)</c>
  546. /// </summary>
  547. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
  548. [Conditional("JETBRAINS_ANNOTATIONS")]
  549. public sealed class AspMvcPartialViewAttribute : PathReferenceAttribute { }
  550. /// <summary>
  551. /// ASP.NET MVC attribute. Allows disabling inspections for MVC views within a class or a method
  552. /// </summary>
  553. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
  554. [Conditional("JETBRAINS_ANNOTATIONS")]
  555. public sealed class AspMvcSupressViewErrorAttribute : Attribute { }
  556. /// <summary>
  557. /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template.
  558. /// Use this attribute for custom wrappers similar to
  559. /// <c>System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String)</c>
  560. /// </summary>
  561. [AttributeUsage(AttributeTargets.Parameter)]
  562. [Conditional("JETBRAINS_ANNOTATIONS")]
  563. public sealed class AspMvcDisplayTemplateAttribute : Attribute { }
  564. /// <summary>
  565. /// ASP.NET MVC attribute. Indicates that a parameter is an MVC editor template.
  566. /// Use this attribute for custom wrappers similar to
  567. /// <c>System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String)</c>
  568. /// </summary>
  569. [AttributeUsage(AttributeTargets.Parameter)]
  570. [Conditional("JETBRAINS_ANNOTATIONS")]
  571. public sealed class AspMvcEditorTemplateAttribute : Attribute { }
  572. /// <summary>
  573. /// ASP.NET MVC attribute. Indicates that a parameter is an MVC template.
  574. /// Use this attribute for custom wrappers similar to
  575. /// <c>System.ComponentModel.DataAnnotations.UIHintAttribute(System.String)</c>
  576. /// </summary>
  577. [AttributeUsage(AttributeTargets.Parameter)]
  578. [Conditional("JETBRAINS_ANNOTATIONS")]
  579. public sealed class AspMvcTemplateAttribute : Attribute { }
  580. /// <summary>
  581. /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter
  582. /// is an MVC view. If applied to a method, the MVC view name is calculated implicitly
  583. /// from the context. Use this attribute for custom wrappers similar to
  584. /// <c>System.Web.Mvc.Controller.View(Object)</c>
  585. /// </summary>
  586. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
  587. [Conditional("JETBRAINS_ANNOTATIONS")]
  588. public sealed class AspMvcViewAttribute : PathReferenceAttribute { }
  589. /// <summary>
  590. /// ASP.NET MVC attribute. When applied to a parameter of an attribute,
  591. /// indicates that this parameter is an MVC action name
  592. /// </summary>
  593. /// <example><code>
  594. /// [ActionName("Foo")]
  595. /// public ActionResult Login(string returnUrl) {
  596. /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK
  597. /// return RedirectToAction("Bar"); // Error: Cannot resolve action
  598. /// }
  599. /// </code></example>
  600. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
  601. [Conditional("JETBRAINS_ANNOTATIONS")]
  602. public sealed class AspMvcActionSelectorAttribute : Attribute { }
  603. [AttributeUsage(
  604. AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)]
  605. [Conditional("JETBRAINS_ANNOTATIONS")]
  606. public sealed class HtmlElementAttributesAttribute : Attribute
  607. {
  608. public HtmlElementAttributesAttribute() { }
  609. public HtmlElementAttributesAttribute(string name)
  610. {
  611. Name = name;
  612. }
  613. public string Name { get; private set; }
  614. }
  615. [AttributeUsage(
  616. AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)]
  617. [Conditional("JETBRAINS_ANNOTATIONS")]
  618. public sealed class HtmlAttributeValueAttribute : Attribute
  619. {
  620. public HtmlAttributeValueAttribute([NotNull] string name)
  621. {
  622. Name = name;
  623. }
  624. [NotNull]
  625. public string Name { get; private set; }
  626. }
  627. /// <summary>
  628. /// Razor attribute. Indicates that a parameter or a method is a Razor section.
  629. /// Use this attribute for custom wrappers similar to
  630. /// <c>System.Web.WebPages.WebPageBase.RenderSection(String)</c>
  631. /// </summary>
  632. [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)]
  633. [Conditional("JETBRAINS_ANNOTATIONS")]
  634. public sealed class RazorSectionAttribute : Attribute { }
  635. /// <summary>
  636. /// Indicates how method invocation affects content of the collection
  637. /// </summary>
  638. [AttributeUsage(AttributeTargets.Method)]
  639. [Conditional("JETBRAINS_ANNOTATIONS")]
  640. public sealed class CollectionAccessAttribute : Attribute
  641. {
  642. public CollectionAccessAttribute(CollectionAccessType collectionAccessType)
  643. {
  644. CollectionAccessType = collectionAccessType;
  645. }
  646. public CollectionAccessType CollectionAccessType { get; private set; }
  647. }
  648. [Flags]
  649. public enum CollectionAccessType
  650. {
  651. /// <summary>Method does not use or modify content of the collection</summary>
  652. None = 0,
  653. /// <summary>Method only reads content of the collection but does not modify it</summary>
  654. Read = 1,
  655. /// <summary>Method can change content of the collection but does not add new elements</summary>
  656. ModifyExistingContent = 2,
  657. /// <summary>Method can add new elements to the collection</summary>
  658. UpdatedContent = ModifyExistingContent | 4
  659. }
  660. /// <summary>
  661. /// Indicates that the marked method is assertion method, i.e. it halts control flow if
  662. /// one of the conditions is satisfied. To set the condition, mark one of the parameters with
  663. /// <see cref="AssertionConditionAttribute"/> attribute
  664. /// </summary>
  665. [AttributeUsage(AttributeTargets.Method)]
  666. [Conditional("JETBRAINS_ANNOTATIONS")]
  667. public sealed class AssertionMethodAttribute : Attribute { }
  668. /// <summary>
  669. /// Indicates the condition parameter of the assertion method. The method itself should be
  670. /// marked by <see cref="AssertionMethodAttribute"/> attribute. The mandatory argument of
  671. /// the attribute is the assertion type.
  672. /// </summary>
  673. [AttributeUsage(AttributeTargets.Parameter)]
  674. [Conditional("JETBRAINS_ANNOTATIONS")]
  675. public sealed class AssertionConditionAttribute : Attribute
  676. {
  677. public AssertionConditionAttribute(AssertionConditionType conditionType)
  678. {
  679. ConditionType = conditionType;
  680. }
  681. public AssertionConditionType ConditionType { get; private set; }
  682. }
  683. /// <summary>
  684. /// Specifies assertion type. If the assertion method argument satisfies the condition,
  685. /// then the execution continues. Otherwise, execution is assumed to be halted
  686. /// </summary>
  687. public enum AssertionConditionType
  688. {
  689. /// <summary>Marked parameter should be evaluated to true</summary>
  690. IS_TRUE = 0,
  691. /// <summary>Marked parameter should be evaluated to false</summary>
  692. IS_FALSE = 1,
  693. /// <summary>Marked parameter should be evaluated to null value</summary>
  694. IS_NULL = 2,
  695. /// <summary>Marked parameter should be evaluated to not null value</summary>
  696. IS_NOT_NULL = 3,
  697. }
  698. /// <summary>
  699. /// Indicates that the marked method unconditionally terminates control flow execution.
  700. /// For example, it could unconditionally throw exception
  701. /// </summary>
  702. [Obsolete("Use [ContractAnnotation('=> halt')] instead")]
  703. [AttributeUsage(AttributeTargets.Method)]
  704. [Conditional("JETBRAINS_ANNOTATIONS")]
  705. public sealed class TerminatesProgramAttribute : Attribute { }
  706. /// <summary>
  707. /// Indicates that method is pure LINQ method, with postponed enumeration (like Enumerable.Select,
  708. /// .Where). This annotation allows inference of [InstantHandle] annotation for parameters
  709. /// of delegate type by analyzing LINQ method chains.
  710. /// </summary>
  711. [AttributeUsage(AttributeTargets.Method)]
  712. [Conditional("JETBRAINS_ANNOTATIONS")]
  713. public sealed class LinqTunnelAttribute : Attribute { }
  714. /// <summary>
  715. /// Indicates that IEnumerable, passed as parameter, is not enumerated.
  716. /// </summary>
  717. [AttributeUsage(AttributeTargets.Parameter)]
  718. [Conditional("JETBRAINS_ANNOTATIONS")]
  719. public sealed class NoEnumerationAttribute : Attribute { }
  720. /// <summary>
  721. /// Indicates that parameter is regular expression pattern.
  722. /// </summary>
  723. [AttributeUsage(AttributeTargets.Parameter)]
  724. [Conditional("JETBRAINS_ANNOTATIONS")]
  725. public sealed class RegexPatternAttribute : Attribute { }
  726. /// <summary>
  727. /// XAML attribute. Indicates the type that has <c>ItemsSource</c> property and should be
  728. /// treated as <c>ItemsControl</c>-derived type, to enable inner items <c>DataContext</c>
  729. /// type resolve.
  730. /// </summary>
  731. [AttributeUsage(AttributeTargets.Class)]
  732. [Conditional("JETBRAINS_ANNOTATIONS")]
  733. public sealed class XamlItemsControlAttribute : Attribute { }
  734. /// <summary>
  735. /// XAML attibute. Indicates the property of some <c>BindingBase</c>-derived type, that
  736. /// is used to bind some item of <c>ItemsControl</c>-derived type. This annotation will
  737. /// enable the <c>DataContext</c> type resolve for XAML bindings for such properties.
  738. /// </summary>
  739. /// <remarks>
  740. /// Property should have the tree ancestor of the <c>ItemsControl</c> type or
  741. /// marked with the <see cref="XamlItemsControlAttribute"/> attribute.
  742. /// </remarks>
  743. [AttributeUsage(AttributeTargets.Property)]
  744. [Conditional("JETBRAINS_ANNOTATIONS")]
  745. public sealed class XamlItemBindingOfItemsControlAttribute : Attribute { }
  746. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  747. [Conditional("JETBRAINS_ANNOTATIONS")]
  748. public sealed class AspChildControlTypeAttribute : Attribute
  749. {
  750. public AspChildControlTypeAttribute(string tagName, Type controlType)
  751. {
  752. TagName = tagName;
  753. ControlType = controlType;
  754. }
  755. public string TagName { get; private set; }
  756. public Type ControlType { get; private set; }
  757. }
  758. [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
  759. [Conditional("JETBRAINS_ANNOTATIONS")]
  760. public sealed class AspDataFieldAttribute : Attribute { }
  761. [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
  762. [Conditional("JETBRAINS_ANNOTATIONS")]
  763. public sealed class AspDataFieldsAttribute : Attribute { }
  764. [AttributeUsage(AttributeTargets.Property)]
  765. [Conditional("JETBRAINS_ANNOTATIONS")]
  766. public sealed class AspMethodPropertyAttribute : Attribute { }
  767. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  768. [Conditional("JETBRAINS_ANNOTATIONS")]
  769. public sealed class AspRequiredAttributeAttribute : Attribute
  770. {
  771. public AspRequiredAttributeAttribute([NotNull] string attribute)
  772. {
  773. Attribute = attribute;
  774. }
  775. public string Attribute { get; private set; }
  776. }
  777. [AttributeUsage(AttributeTargets.Property)]
  778. [Conditional("JETBRAINS_ANNOTATIONS")]
  779. public sealed class AspTypePropertyAttribute : Attribute
  780. {
  781. public bool CreateConstructorReferences { get; private set; }
  782. public AspTypePropertyAttribute(bool createConstructorReferences)
  783. {
  784. CreateConstructorReferences = createConstructorReferences;
  785. }
  786. }
  787. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  788. [Conditional("JETBRAINS_ANNOTATIONS")]
  789. public sealed class RazorImportNamespaceAttribute : Attribute
  790. {
  791. public RazorImportNamespaceAttribute(string name)
  792. {
  793. Name = name;
  794. }
  795. public string Name { get; private set; }
  796. }
  797. [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
  798. [Conditional("JETBRAINS_ANNOTATIONS")]
  799. public sealed class RazorInjectionAttribute : Attribute
  800. {
  801. public RazorInjectionAttribute(string type, string fieldName)
  802. {
  803. Type = type;
  804. FieldName = fieldName;
  805. }
  806. public string Type { get; private set; }
  807. public string FieldName { get; private set; }
  808. }
  809. [AttributeUsage(AttributeTargets.Method)]
  810. [Conditional("JETBRAINS_ANNOTATIONS")]
  811. public sealed class RazorHelperCommonAttribute : Attribute { }
  812. [AttributeUsage(AttributeTargets.Property)]
  813. [Conditional("JETBRAINS_ANNOTATIONS")]
  814. public sealed class RazorLayoutAttribute : Attribute { }
  815. [AttributeUsage(AttributeTargets.Method)]
  816. [Conditional("JETBRAINS_ANNOTATIONS")]
  817. public sealed class RazorWriteLiteralMethodAttribute : Attribute { }
  818. [AttributeUsage(AttributeTargets.Method)]
  819. [Conditional("JETBRAINS_ANNOTATIONS")]
  820. public sealed class RazorWriteMethodAttribute : Attribute { }
  821. [AttributeUsage(AttributeTargets.Parameter)]
  822. [Conditional("JETBRAINS_ANNOTATIONS")]
  823. public sealed class RazorWriteMethodParameterAttribute : Attribute { }
  824. /// <summary>
  825. /// Prevents the Member Reordering feature from tossing members of the marked class.
  826. /// </summary>
  827. /// <remarks>
  828. /// The attribute must be mentioned in your member reordering patterns.
  829. /// </remarks>
  830. [AttributeUsage(AttributeTargets.All)]
  831. [Conditional("JETBRAINS_ANNOTATIONS")]
  832. public sealed class NoReorder : Attribute { }
  833. }
  834. #endif