summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Diagnostics/Contracts
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Diagnostics/Contracts')
-rw-r--r--src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs48
-rw-r--r--src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs59
2 files changed, 62 insertions, 45 deletions
diff --git a/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs b/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs
index 93d6c48701..76b15197f2 100644
--- a/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs
+++ b/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs
@@ -27,7 +27,6 @@
#else // CLR
#define FEATURE_UNTRUSTED_CALLERS
#define FEATURE_RELIABILITY_CONTRACTS
-#define FEATURE_SERIALIZATION
#endif
using System;
@@ -43,8 +42,8 @@ using System.Runtime.ConstrainedExecution;
using System.Security;
#endif
-namespace System.Diagnostics.Contracts {
-
+namespace System.Diagnostics.Contracts
+{
#region Attributes
/// <summary>
@@ -71,7 +70,8 @@ namespace System.Diagnostics.Contracts {
_typeWithContracts = typeContainingContracts;
}
- public Type TypeContainingContracts {
+ public Type TypeContainingContracts
+ {
get { return _typeWithContracts; }
}
}
@@ -90,7 +90,8 @@ namespace System.Diagnostics.Contracts {
_typeIAmAContractFor = typeContractsAreFor;
}
- public Type TypeContractsAreFor {
+ public Type TypeContractsAreFor
+ {
get { return _typeIAmAContractFor; }
}
}
@@ -176,7 +177,8 @@ namespace System.Diagnostics.Contracts {
public ContractVerificationAttribute(bool value) { _value = value; }
- public bool Value {
+ public bool Value
+ {
get { return _value; }
}
}
@@ -197,7 +199,8 @@ namespace System.Diagnostics.Contracts {
_publicName = name;
}
- public String Name {
+ public String Name
+ {
get { return _publicName; }
}
}
@@ -247,19 +250,23 @@ namespace System.Diagnostics.Contracts {
_value = value;
}
- public String Category {
+ public String Category
+ {
get { return _category; }
}
- public String Setting {
+ public String Setting
+ {
get { return _setting; }
}
- public bool Enabled {
+ public bool Enabled
+ {
get { return _enabled; }
}
- public String Value {
+ public String Value
+ {
get { return _value; }
}
}
@@ -296,7 +303,8 @@ namespace System.Diagnostics.Contracts {
#endif
public static void Assume(bool condition)
{
- if (!condition) {
+ if (!condition)
+ {
ReportFailure(ContractFailureKind.Assume, null, null, null);
}
}
@@ -316,7 +324,8 @@ namespace System.Diagnostics.Contracts {
#endif
public static void Assume(bool condition, String userMessage)
{
- if (!condition) {
+ if (!condition)
+ {
ReportFailure(ContractFailureKind.Assume, userMessage, null, null);
}
}
@@ -630,8 +639,8 @@ namespace System.Diagnostics.Contracts {
public static bool ForAll(int fromInclusive, int toExclusive, Predicate<int> predicate)
{
if (fromInclusive > toExclusive)
-#if INSIDE_CLR
- throw new ArgumentException(Environment.GetResourceString("Argument_ToExclusiveLessThanFromExclusive"));
+#if CORECLR
+ throw new ArgumentException(SR.Argument_ToExclusiveLessThanFromExclusive);
#else
throw new ArgumentException("fromInclusive must be less than or equal to toExclusive.");
#endif
@@ -690,8 +699,8 @@ namespace System.Diagnostics.Contracts {
public static bool Exists(int fromInclusive, int toExclusive, Predicate<int> predicate)
{
if (fromInclusive > toExclusive)
-#if INSIDE_CLR
- throw new ArgumentException(Environment.GetResourceString("Argument_ToExclusiveLessThanFromExclusive"));
+#if CORECLR
+ throw new ArgumentException(SR.Argument_ToExclusiveLessThanFromExclusive);
#else
throw new ArgumentException("fromInclusive must be less than or equal to toExclusive.");
#endif
@@ -769,7 +778,8 @@ namespace System.Diagnostics.Contracts {
#endregion
}
- public enum ContractFailureKind {
+ public enum ContractFailureKind
+ {
Precondition,
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Postcondition")]
Postcondition,
@@ -779,8 +789,6 @@ namespace System.Diagnostics.Contracts {
Assert,
Assume,
}
-
-
}
// Note: In .NET FX 4.5, we duplicated the ContractHelper class in the System.Runtime.CompilerServices
diff --git a/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs b/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs
index 5f4de4f666..09d1e6baca 100644
--- a/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs
+++ b/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs
@@ -20,7 +20,6 @@
#else // CLR
#define FEATURE_UNTRUSTED_CALLERS
#define FEATURE_RELIABILITY_CONTRACTS
-#define FEATURE_SERIALIZATION
#endif
using System;
@@ -37,8 +36,8 @@ using System.Runtime.ConstrainedExecution;
using System.Security;
#endif
-namespace System.Diagnostics.Contracts {
-
+namespace System.Diagnostics.Contracts
+{
public static partial class Contract
{
#region Private Methods
@@ -74,7 +73,7 @@ namespace System.Diagnostics.Contracts {
if (probablyNotRewritten == null)
probablyNotRewritten = thisAssembly;
String simpleName = probablyNotRewritten.GetName().Name;
- System.Runtime.CompilerServices.ContractHelper.TriggerFailure(kind, Environment.GetResourceString("MustUseCCRewrite", contractKind, simpleName), null, null, null);
+ System.Runtime.CompilerServices.ContractHelper.TriggerFailure(kind, SR.Format(SR.MustUseCCRewrite, contractKind, simpleName), null, null, null);
_assertingMustUseRewriter = false;
}
@@ -96,7 +95,7 @@ namespace System.Diagnostics.Contracts {
static partial void ReportFailure(ContractFailureKind failureKind, String userMessage, String conditionText, Exception innerException)
{
if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume)
- throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", failureKind), nameof(failureKind));
+ throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, failureKind), nameof(failureKind));
Contract.EndContractBlock();
// displayMessage == null means: yes we handled it. Otherwise it is the localized failure message
@@ -116,15 +115,18 @@ namespace System.Diagnostics.Contracts {
/// full trust, because it will inform you of bugs in the appdomain and because the event handler
/// could allow you to continue execution.
/// </summary>
- public static event EventHandler<ContractFailedEventArgs> ContractFailed {
+ public static event EventHandler<ContractFailedEventArgs> ContractFailed
+ {
#if FEATURE_UNTRUSTED_CALLERS
#endif
- add {
+ add
+ {
System.Runtime.CompilerServices.ContractHelper.InternalContractFailed += value;
}
#if FEATURE_UNTRUSTED_CALLERS
#endif
- remove {
+ remove
+ {
System.Runtime.CompilerServices.ContractHelper.InternalContractFailed -= value;
}
}
@@ -159,7 +161,8 @@ namespace System.Diagnostics.Contracts {
public Exception OriginalException { get { return _originalException; } }
// Whether the event handler "handles" this contract failure, or to fail via escalation policy.
- public bool Handled {
+ public bool Handled
+ {
get { return _handled; }
}
@@ -170,7 +173,8 @@ namespace System.Diagnostics.Contracts {
_handled = true;
}
- public bool Unwind {
+ public bool Unwind
+ {
get { return _unwind; }
}
@@ -186,9 +190,9 @@ namespace System.Diagnostics.Contracts {
[SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic")]
internal sealed class ContractException : Exception
{
- readonly ContractFailureKind _Kind;
- readonly string _UserMessage;
- readonly string _Condition;
+ private readonly ContractFailureKind _Kind;
+ private readonly string _UserMessage;
+ private readonly string _Condition;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public ContractFailureKind Kind { get { return _Kind; } }
@@ -209,9 +213,9 @@ namespace System.Diagnostics.Contracts {
: base(failure, innerException)
{
HResult = System.Runtime.CompilerServices.ContractHelper.COR_E_CODECONTRACTFAILED;
- this._Kind = kind;
- this._UserMessage = userMessage;
- this._Condition = condition;
+ _Kind = kind;
+ _UserMessage = userMessage;
+ _Condition = condition;
}
private ContractException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
@@ -259,7 +263,8 @@ namespace System.Runtime.CompilerServices
{
#if FEATURE_UNTRUSTED_CALLERS
#endif
- add {
+ add
+ {
// Eagerly prepare each event handler _marked with a reliability contract_, to
// attempt to reduce out of memory exceptions while reporting contract violations.
// This only works if the new handler obeys the constraints placed on
@@ -275,7 +280,8 @@ namespace System.Runtime.CompilerServices
}
#if FEATURE_UNTRUSTED_CALLERS
#endif
- remove {
+ remove
+ {
lock (lockObject)
{
contractFailedEvent -= value;
@@ -302,7 +308,7 @@ namespace System.Runtime.CompilerServices
static partial void RaiseContractFailedEventImplementation(ContractFailureKind failureKind, String userMessage, String conditionText, Exception innerException, ref string resultFailureMessage)
{
if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume)
- throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", failureKind), nameof(failureKind));
+ throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, failureKind), nameof(failureKind));
Contract.EndContractBlock();
string returnValue;
@@ -369,13 +375,14 @@ namespace System.Runtime.CompilerServices
// "Assert On Failure" but used in a process that can't pop up asserts, like an
// NT Service).
- if (!Environment.UserInteractive) {
+ if (!Environment.UserInteractive)
+ {
throw new ContractException(kind, displayMessage, userMessage, conditionText, innerException);
}
// May need to rethink Assert.Fail w/ TaskDialogIndirect as a model. Window title. Main instruction. Content. Expanded info.
// Optional info like string for collapsed text vs. expanded text.
- String windowTitle = Environment.GetResourceString(GetResourceNameForFailure(kind));
+ String windowTitle = SR.GetResourceString(GetResourceNameForFailure(kind));
const int numStackFramesToSkip = 2; // To make stack traces easier to read
System.Diagnostics.Assert.Fail(conditionText, displayMessage, windowTitle, COR_E_CODECONTRACTFAILED, StackTrace.TraceFormat.Normal, numStackFramesToSkip);
// If we got here, the user selected Ignore. Continue.
@@ -430,12 +437,14 @@ namespace System.Runtime.CompilerServices
// on Silverlight we may not be able to look up a friendly string for the
// error message. Let's leverage Silverlight's default error message there.
String failureMessage;
- if (!String.IsNullOrEmpty(conditionText)) {
+ if (!String.IsNullOrEmpty(conditionText))
+ {
resourceName += "_Cnd";
- failureMessage = Environment.GetResourceString(resourceName, conditionText);
+ failureMessage = SR.Format(SR.GetResourceString(resourceName), conditionText);
}
- else {
- failureMessage = Environment.GetResourceString(resourceName);
+ else
+ {
+ failureMessage = SR.GetResourceString(resourceName);
}
// Now add in the user message, if present.