Annotations.cs 37 KB

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