comparison Source/Properties/JetBrains.Annotations.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections.Generic;
3
4 namespace JetBrains.Annotations
5 {
6 /// <summary>
7 /// Indicates that marked method builds string by format pattern and (optional) arguments.
8 /// Parameter, which contains format string, should be given in constructor.
9 /// The format string should be in <see cref="string.Format(IFormatProvider,string,object[])"/> -like form
10 /// </summary>
11 [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
12 internal sealed class StringFormatMethodAttribute : Attribute
13 {
14 private readonly string _formatParameterName;
15
16 /// <summary>
17 /// Initializes new instance of StringFormatMethodAttribute
18 /// </summary>
19 /// <param name="formatParameterName">Specifies which parameter of an annotated method should be treated as format-string</param>
20 public StringFormatMethodAttribute(string formatParameterName)
21 {
22 _formatParameterName = formatParameterName;
23 }
24
25 /// <summary>
26 /// Gets format parameter name
27 /// </summary>
28 public string FormatParameterName
29 {
30 get { return _formatParameterName; }
31 }
32 }
33
34 /// <summary>
35 /// Indicates that the function argument should be string literal and match one of the parameters of the caller function.
36 /// For example, <see cref="ArgumentNullException"/> has such parameter.
37 /// </summary>
38 [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
39 internal sealed class InvokerParameterNameAttribute : Attribute
40 {
41 }
42
43 /// <summary>
44 /// Indicates that the marked method is assertion method, i.e. it halts control flow if one of the conditions is satisfied.
45 /// To set the condition, mark one of the parameters with <see cref="AssertionConditionAttribute"/> attribute
46 /// </summary>
47 /// <seealso cref="AssertionConditionAttribute"/>
48 [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
49 internal sealed class AssertionMethodAttribute : Attribute
50 {
51 }
52
53 /// <summary>
54 /// Indicates the condition parameter of the assertion method.
55 /// The method itself should be marked by <see cref="AssertionMethodAttribute"/> attribute.
56 /// The mandatory argument of the attribute is the assertion type.
57 /// </summary>
58 /// <seealso cref="AssertionConditionType"/>
59 [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
60 internal sealed class AssertionConditionAttribute : Attribute
61 {
62 private readonly AssertionConditionType _conditionType;
63
64 /// <summary>
65 /// Initializes new instance of AssertionConditionAttribute
66 /// </summary>
67 /// <param name="conditionType">Specifies condition type</param>
68 public AssertionConditionAttribute(AssertionConditionType conditionType)
69 {
70 _conditionType = conditionType;
71 }
72
73 /// <summary>
74 /// Gets condition type
75 /// </summary>
76 public AssertionConditionType ConditionType
77 {
78 get { return _conditionType; }
79 }
80 }
81
82 /// <summary>
83 /// Specifies assertion type. If the assertion method argument satisifes the condition, then the execution continues.
84 /// Otherwise, execution is assumed to be halted
85 /// </summary>
86 internal enum AssertionConditionType
87 {
88 /// <summary>
89 /// Indicates that the marked parameter should be evaluated to true
90 /// </summary>
91 IS_TRUE = 0,
92
93 /// <summary>
94 /// Indicates that the marked parameter should be evaluated to false
95 /// </summary>
96 IS_FALSE = 1,
97
98 /// <summary>
99 /// Indicates that the marked parameter should be evaluated to null value
100 /// </summary>
101 IS_NULL = 2,
102
103 /// <summary>
104 /// Indicates that the marked parameter should be evaluated to not null value
105 /// </summary>
106 IS_NOT_NULL = 3,
107 }
108
109 /// <summary>
110 /// Indicates that the marked method unconditionally terminates control flow execution.
111 /// For example, it could unconditionally throw exception
112 /// </summary>
113 [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
114 internal sealed class TerminatesProgramAttribute : Attribute
115 {
116 }
117
118 /// <summary>
119 /// Indicates that the value of marked element could be <c>null</c> sometimes, so the check for <c>null</c> is necessary before its usage
120 /// </summary>
121 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
122 internal sealed class CanBeNullAttribute : Attribute
123 {
124 }
125
126 /// <summary>
127 /// Indicates that the value of marked element could never be <c>null</c>
128 /// </summary>
129 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
130 internal sealed class NotNullAttribute : Attribute
131 {
132 }
133
134 /// <summary>
135 /// Indicates that the value of marked type (or its derivatives) cannot be compared using '==' or '!=' operators.
136 /// There is only exception to compare with <c>null</c>, it is permitted
137 /// </summary>
138 [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
139 internal sealed class CannotApplyEqualityOperatorAttribute : Attribute
140 {
141 }
142
143 /// <summary>
144 /// When applied to target attribute, specifies a requirement for any type which is marked with
145 /// target attribute to implement or inherit specific type or types
146 /// </summary>
147 /// <example>
148 /// <code>
149 /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement
150 /// public class ComponentAttribute : Attribute
151 /// {}
152 ///
153 /// [Component] // ComponentAttribute requires implementing IComponent interface
154 /// public class MyComponent : IComponent
155 /// {}
156 /// </code>
157 /// </example>
158 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
159 [BaseTypeRequired(typeof(Attribute))]
160 internal sealed class BaseTypeRequiredAttribute : Attribute
161 {
162 private readonly Type[] _baseTypes;
163
164 /// <summary>
165 /// Initializes new instance of BaseTypeRequiredAttribute
166 /// </summary>
167 /// <param name="baseType">Specifies which types are required</param>
168 public BaseTypeRequiredAttribute(Type baseType)
169 : this(new Type[] { baseType })
170 {
171 }
172
173 /// <summary>
174 /// Initializes new instance of BaseTypeRequiredAttribute
175 /// </summary>
176 /// <param name="baseTypes">Specifies which types are required</param>
177 public BaseTypeRequiredAttribute(params Type[] baseTypes)
178 {
179 _baseTypes = baseTypes;
180 }
181
182 /// <summary>
183 /// Gets enumerations of specified base types
184 /// </summary>
185 public IEnumerable<Type> BaseTypes
186 {
187 get { return _baseTypes; }
188 }
189 }
190
191 /// <summary>
192 /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library),
193 /// so this symbol will not be marked as unused (as well as by other usage inspections)
194 /// </summary>
195 [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
196 internal class UsedImplicitlyAttribute : Attribute
197 {
198 readonly ImplicitUseFlags _flags;
199 /// <summary>
200 /// Gets value indicating what is meant to be used
201 /// </summary>
202 [UsedImplicitly]
203 public ImplicitUseFlags Flags
204 {
205 get { return _flags; }
206 }
207
208 /// <summary>
209 /// Initializes new instance of UsedImplicitlyAttribute
210 /// </summary>
211 public UsedImplicitlyAttribute()
212 : this(ImplicitUseFlags.Default)
213 {
214 }
215
216 /// <summary>
217 /// Initializes new instance of UsedImplicitlyAttribute with specified flags
218 /// </summary>
219 /// <param name="flags">Value of type <see cref="ImplicitUseFlags"/> indicating usage kind</param>
220 public UsedImplicitlyAttribute(ImplicitUseFlags flags)
221 {
222 _flags = flags;
223 }
224 }
225
226 /// <summary>
227 /// Should be used on attributes and causes ReSharper to not mark symbols marked with such attributes as unused (as well as by other usage inspections)
228 /// </summary>
229 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
230 internal class MeansImplicitUseAttribute : Attribute
231 {
232 readonly ImplicitUseFlags _flags;
233 /// <summary>
234 /// Gets value indicating what is meant to be used
235 /// </summary>
236 [UsedImplicitly]
237 public ImplicitUseFlags Flags
238 {
239 get { return _flags; }
240 }
241
242 /// <summary>
243 /// Initializes new instance of MeansImplicitUseAttribute
244 /// </summary>
245 [UsedImplicitly]
246 public MeansImplicitUseAttribute()
247 : this(ImplicitUseFlags.Default)
248 {
249 }
250
251 /// <summary>
252 /// Initializes new instance of MeansImplicitUseAttribute with specified flags
253 /// </summary>
254 /// <param name="flags">Value of type <see cref="ImplicitUseFlags"/> indicating usage kind</param>
255 [UsedImplicitly]
256 public MeansImplicitUseAttribute(ImplicitUseFlags flags)
257 {
258 _flags = flags;
259 }
260 }
261
262 /// <summary>
263 /// Specify what is considered used implicitly when marked with <see cref="MeansImplicitUseAttribute"/> or <see cref="UsedImplicitlyAttribute"/>
264 /// </summary>
265 [Flags]
266 internal enum ImplicitUseFlags
267 {
268 /// <summary>
269 /// Only entity marked with attribute considered used
270 /// </summary>
271 Default = 0,
272
273 /// <summary>
274 /// Entity marked with attribute and all its members considered used
275 /// </summary>
276 IncludeMembers = 1
277 }
278
279 [AttributeUsage(AttributeTargets.Parameter, Inherited = true)]
280 internal sealed class InstantHandleAttribute : Attribute { }
281 }