using System; using System.Collections.Generic; namespace JetBrains.Annotations { /// /// Indicates that marked method builds string by format pattern and (optional) arguments. /// Parameter, which contains format string, should be given in constructor. /// The format string should be in -like form /// [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] internal sealed class StringFormatMethodAttribute : Attribute { private readonly string _formatParameterName; /// /// Initializes new instance of StringFormatMethodAttribute /// /// Specifies which parameter of an annotated method should be treated as format-string public StringFormatMethodAttribute(string formatParameterName) { _formatParameterName = formatParameterName; } /// /// Gets format parameter name /// public string FormatParameterName { get { return _formatParameterName; } } } /// /// Indicates that the function argument should be string literal and match one of the parameters of the caller function. /// For example, has such parameter. /// [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] internal sealed class InvokerParameterNameAttribute : Attribute { } /// /// Indicates that the marked method is assertion method, i.e. it halts control flow if one of the conditions is satisfied. /// To set the condition, mark one of the parameters with attribute /// /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] internal sealed class AssertionMethodAttribute : Attribute { } /// /// Indicates the condition parameter of the assertion method. /// The method itself should be marked by attribute. /// The mandatory argument of the attribute is the assertion type. /// /// [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] internal sealed class AssertionConditionAttribute : Attribute { private readonly AssertionConditionType _conditionType; /// /// Initializes new instance of AssertionConditionAttribute /// /// Specifies condition type public AssertionConditionAttribute(AssertionConditionType conditionType) { _conditionType = conditionType; } /// /// Gets condition type /// public AssertionConditionType ConditionType { get { return _conditionType; } } } /// /// Specifies assertion type. If the assertion method argument satisifes the condition, then the execution continues. /// Otherwise, execution is assumed to be halted /// internal enum AssertionConditionType { /// /// Indicates that the marked parameter should be evaluated to true /// IS_TRUE = 0, /// /// Indicates that the marked parameter should be evaluated to false /// IS_FALSE = 1, /// /// Indicates that the marked parameter should be evaluated to null value /// IS_NULL = 2, /// /// Indicates that the marked parameter should be evaluated to not null value /// IS_NOT_NULL = 3, } /// /// Indicates that the marked method unconditionally terminates control flow execution. /// For example, it could unconditionally throw exception /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] internal sealed class TerminatesProgramAttribute : Attribute { } /// /// Indicates that the value of marked element could be null sometimes, so the check for null is necessary before its usage /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] internal sealed class CanBeNullAttribute : Attribute { } /// /// Indicates that the value of marked element could never be null /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] internal sealed class NotNullAttribute : Attribute { } /// /// Indicates that the value of marked type (or its derivatives) cannot be compared using '==' or '!=' operators. /// There is only exception to compare with null, it is permitted /// [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)] internal sealed class CannotApplyEqualityOperatorAttribute : Attribute { } /// /// When applied to target attribute, specifies a requirement for any type which is marked with /// target attribute to implement or inherit specific type or types /// /// /// /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement /// public class ComponentAttribute : Attribute /// {} /// /// [Component] // ComponentAttribute requires implementing IComponent interface /// public class MyComponent : IComponent /// {} /// /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] [BaseTypeRequired(typeof(Attribute))] internal sealed class BaseTypeRequiredAttribute : Attribute { private readonly Type[] _baseTypes; /// /// Initializes new instance of BaseTypeRequiredAttribute /// /// Specifies which types are required public BaseTypeRequiredAttribute(Type baseType) : this(new Type[] { baseType }) { } /// /// Initializes new instance of BaseTypeRequiredAttribute /// /// Specifies which types are required public BaseTypeRequiredAttribute(params Type[] baseTypes) { _baseTypes = baseTypes; } /// /// Gets enumerations of specified base types /// public IEnumerable BaseTypes { get { return _baseTypes; } } } /// /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), /// so this symbol will not be marked as unused (as well as by other usage inspections) /// [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] internal class UsedImplicitlyAttribute : Attribute { readonly ImplicitUseFlags _flags; /// /// Gets value indicating what is meant to be used /// [UsedImplicitly] public ImplicitUseFlags Flags { get { return _flags; } } /// /// Initializes new instance of UsedImplicitlyAttribute /// public UsedImplicitlyAttribute() : this(ImplicitUseFlags.Default) { } /// /// Initializes new instance of UsedImplicitlyAttribute with specified flags /// /// Value of type indicating usage kind public UsedImplicitlyAttribute(ImplicitUseFlags flags) { _flags = flags; } } /// /// 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) /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] internal class MeansImplicitUseAttribute : Attribute { readonly ImplicitUseFlags _flags; /// /// Gets value indicating what is meant to be used /// [UsedImplicitly] public ImplicitUseFlags Flags { get { return _flags; } } /// /// Initializes new instance of MeansImplicitUseAttribute /// [UsedImplicitly] public MeansImplicitUseAttribute() : this(ImplicitUseFlags.Default) { } /// /// Initializes new instance of MeansImplicitUseAttribute with specified flags /// /// Value of type indicating usage kind [UsedImplicitly] public MeansImplicitUseAttribute(ImplicitUseFlags flags) { _flags = flags; } } /// /// Specify what is considered used implicitly when marked with or /// [Flags] internal enum ImplicitUseFlags { /// /// Only entity marked with attribute considered used /// Default = 0, /// /// Entity marked with attribute and all its members considered used /// IncludeMembers = 1 } }