1 <?xml version="1.0" encoding="utf-8"?>
2 <Type Name="ContractOptionAttribute" FullName="System.Diagnostics.Contracts.ContractOptionAttribute">
3 <TypeSignature Language="C#" Value="public sealed class ContractOptionAttribute : Attribute" />
4 <TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit ContractOptionAttribute extends System.Attribute" />
6 <AssemblyName>mscorlib</AssemblyName>
7 <AssemblyVersion>4.0.0.0</AssemblyVersion>
10 <BaseTypeName>System.Attribute</BaseTypeName>
15 <AttributeName>System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=false)</AttributeName>
18 <AttributeName>System.Diagnostics.Conditional("CONTRACTS_FULL")</AttributeName>
23 <attribution license="cc4" from="Microsoft" modified="false" />
24 <para>The following table shows the currently supported options.</para>
35 <para>Value/effect</para>
44 <para>inheritance</para>
47 <para>true to turn contract inheritance on; false to turn it off. The default is true.</para>
58 <para>true to turn run-time checking on; false to turn it off. The default is true.</para>
62 <para>You can use this attribute as illustrated in the following examples.</para>
63 <para>To turn off run-time checking for the entire assembly:</para>
64 <code>[assembly:ContractOption("runtime", "checking", false)]</code>
65 <para>To turn run-time contract checking on for a specific type:</para>
66 <code> [ContractOption("runtime", "checking", true)]
67 class TypeWithRuntimeChecking {
71 <para>To turn run-time checking off for a specific method:</para>
72 <code>// Turn off all contract inheritance from interface IList<T>
73 [ContractOption("contract", "inheritance", false)]
74 class MyConcurrentList<T> : IList<T> {
78 [ContractOption("runtime", "checking", false)]
79 public override MyMethod(int x) {
80 // no inherited contracts checked at runtime,
81 // no invariants checked at runtime.
85 [ContractOption("runtime", "checking", false)]
86 public void MethodWithoutRuntimeChecking(...) {
93 <attribution license="cc4" from="Microsoft" modified="false" />
94 <para>Enables you to set contract and tool options at assembly, type, or method granularity.</para>
98 <Member MemberName=".ctor">
99 <MemberSignature Language="C#" Value="public ContractOptionAttribute (string category, string setting, bool enabled);" />
100 <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string category, string setting, bool enabled) cil managed" />
101 <MemberType>Constructor</MemberType>
103 <AssemblyVersion>4.0.0.0</AssemblyVersion>
106 <Parameter Name="category" Type="System.String" />
107 <Parameter Name="setting" Type="System.String" />
108 <Parameter Name="enabled" Type="System.Boolean" />
111 <remarks>To be added.</remarks>
113 <attribution license="cc4" from="Microsoft" modified="false" />
114 <para>Initializes a new instance of the <see cref="T:System.Diagnostics.Contracts.ContractOptionAttribute" /> class by using the provided category, setting, and enable/disable value.</para>
116 <param name="category">
117 <attribution license="cc4" from="Microsoft" modified="false" />The category for the option to be set.</param>
118 <param name="setting">
119 <attribution license="cc4" from="Microsoft" modified="false" />The option setting.</param>
120 <param name="enabled">
121 <attribution license="cc4" from="Microsoft" modified="false" />true to enable the option; false to disable the option.</param>
124 <Member MemberName=".ctor">
125 <MemberSignature Language="C#" Value="public ContractOptionAttribute (string category, string setting, string value);" />
126 <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string category, string setting, string value) cil managed" />
127 <MemberType>Constructor</MemberType>
129 <AssemblyVersion>4.0.0.0</AssemblyVersion>
132 <Parameter Name="category" Type="System.String" />
133 <Parameter Name="setting" Type="System.String" />
134 <Parameter Name="value" Type="System.String" />
138 <attribution license="cc4" from="Microsoft" modified="false" />
139 <para>There are only two category/setting options, and they can be set by either of the constructor overloads. You can use this overload with the same settings as the <see cref="M:System.Diagnostics.Contracts.ContractOptionAttribute.#ctor(System.String,System.String,System.Boolean)" /> overload by specifying "true" or "false" in string format; for example:</para>
140 <code>[ContractOption("contract", "inheritance", “false”)]
141 class MyConcurrentList<T> : IList<T> {
147 <attribution license="cc4" from="Microsoft" modified="false" />
148 <para>Initializes a new instance of the <see cref="T:System.Diagnostics.Contracts.ContractOptionAttribute" /> class by using the provided category, setting, and value.</para>
150 <param name="category">
151 <attribution license="cc4" from="Microsoft" modified="false" />The category of the option to be set.</param>
152 <param name="setting">
153 <attribution license="cc4" from="Microsoft" modified="false" />The option setting.</param>
155 <attribution license="cc4" from="Microsoft" modified="false" />The value for the setting.</param>
158 <Member MemberName="Category">
159 <MemberSignature Language="C#" Value="public string Category { get; }" />
160 <MemberSignature Language="ILAsm" Value=".property instance string Category" />
161 <MemberType>Property</MemberType>
163 <AssemblyVersion>4.0.0.0</AssemblyVersion>
166 <ReturnType>System.String</ReturnType>
169 <value>To be added.</value>
170 <remarks>To be added.</remarks>
172 <attribution license="cc4" from="Microsoft" modified="false" />
173 <para>Gets the category of the option.</para>
177 <Member MemberName="Enabled">
178 <MemberSignature Language="C#" Value="public bool Enabled { get; }" />
179 <MemberSignature Language="ILAsm" Value=".property instance bool Enabled" />
180 <MemberType>Property</MemberType>
182 <AssemblyVersion>4.0.0.0</AssemblyVersion>
185 <ReturnType>System.Boolean</ReturnType>
188 <value>To be added.</value>
189 <remarks>To be added.</remarks>
191 <attribution license="cc4" from="Microsoft" modified="false" />
192 <para>Determines if an option is enabled.</para>
196 <Member MemberName="Setting">
197 <MemberSignature Language="C#" Value="public string Setting { get; }" />
198 <MemberSignature Language="ILAsm" Value=".property instance string Setting" />
199 <MemberType>Property</MemberType>
201 <AssemblyVersion>4.0.0.0</AssemblyVersion>
204 <ReturnType>System.String</ReturnType>
207 <value>To be added.</value>
208 <remarks>To be added.</remarks>
210 <attribution license="cc4" from="Microsoft" modified="false" />
211 <para>Gets the setting for the option.</para>
215 <Member MemberName="Value">
216 <MemberSignature Language="C#" Value="public string Value { get; }" />
217 <MemberSignature Language="ILAsm" Value=".property instance string Value" />
218 <MemberType>Property</MemberType>
220 <AssemblyVersion>4.0.0.0</AssemblyVersion>
223 <ReturnType>System.String</ReturnType>
226 <value>To be added.</value>
227 <remarks>To be added.</remarks>
229 <attribution license="cc4" from="Microsoft" modified="false" />
230 <para>Gets the value for the option.</para>