本文整理汇总了C#中ContractFailureKind类的典型用法代码示例。如果您正苦于以下问题:C# ContractFailureKind类的具体用法?C# ContractFailureKind怎么用?C# ContractFailureKind使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContractFailureKind类属于命名空间,在下文中一共展示了ContractFailureKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertMustUseRewriter
/// <summary>
/// This method is used internally to trigger a failure indicating to the "programmer" that he is using the interface incorrectly.
/// It is NEVER used to indicate failure of actual contracts at runtime.
/// </summary>
#if FEATURE_UNTRUSTED_CALLERS
#endif
static partial void AssertMustUseRewriter(ContractFailureKind kind, String contractKind)
{
//TODO: Implement CodeContract failure mechanics including enabling CCIRewrite
if (t_assertingMustUseRewriter)
{
System.Diagnostics.Debug.Assert(false, "Asserting that we must use the rewriter went reentrant. Didn't rewrite this System.Private.CoreLib?");
return;
}
t_assertingMustUseRewriter = true;
//// For better diagnostics, report which assembly is at fault. Walk up stack and
//// find the first non-mscorlib assembly.
//Assembly thisAssembly = typeof(Contract).Assembly; // In case we refactor mscorlib, use Contract class instead of Object.
//StackTrace stack = new StackTrace();
//Assembly probablyNotRewritten = null;
//for (int i = 0; i < stack.FrameCount; i++)
//{
// Assembly caller = stack.GetFrame(i).GetMethod().DeclaringType.Assembly;
// if (caller != thisAssembly)
// {
// probablyNotRewritten = caller;
// break;
// }
//}
//if (probablyNotRewritten == null)
// probablyNotRewritten = thisAssembly;
//String simpleName = probablyNotRewritten.GetName().Name;
String simpleName = "System.Private.CoreLib";
System.Runtime.CompilerServices.ContractHelper.TriggerFailure(kind, SR.Format(SR.MustUseCCRewrite, contractKind, simpleName), null, null, null);
t_assertingMustUseRewriter = false;
}
示例2: OnContractFailure
public virtual bool OnContractFailure(String stackTrace, ContractFailureKind contractFailureKind, String displayMessage, String userMessage, String conditionText, Exception innerException)
{
Debug.WriteLine("Assertion failed: " + (displayMessage == null ? "" : displayMessage));
if (Debugger.IsAttached)
Debugger.Break();
return false;
}
示例3: KindToString
private static string KindToString(ContractFailureKind kind)
{
var kindString = "unknown";
switch (kind)
{
case ContractFailureKind.Assert:
kindString = "Contract.Assert";
break;
case ContractFailureKind.Assume:
kindString = "Contract.Assume";
break;
case ContractFailureKind.Invariant:
kindString = "Contract.Invariant";
break;
case ContractFailureKind.Postcondition:
kindString = "Contract.Postcondition";
break;
case ContractFailureKind.PostconditionOnException:
kindString = "Contract.PostconditionOnException";
break;
case ContractFailureKind.Precondition:
kindString = "Contract.Precondition";
break;
}
return kindString;
}
示例4: AssertMustUseRewriter
static partial void AssertMustUseRewriter(ContractFailureKind kind, String contractKind)
{
if (_assertingMustUseRewriter)
System.Diagnostics.Assert.Fail("Asserting that we must use the rewriter went reentrant.", "Didn't rewrite this mscorlib?");
_assertingMustUseRewriter = true;
// For better diagnostics, report which assembly is at fault. Walk up stack and
// find the first non-mscorlib assembly.
Assembly thisAssembly = typeof(Contract).Assembly; // In case we refactor mscorlib, use Contract class instead of Object.
StackTrace stack = new StackTrace();
Assembly probablyNotRewritten = null;
for (int i = 0; i < stack.FrameCount; i++)
{
Assembly caller = stack.GetFrame(i).GetMethod().DeclaringType.Assembly;
if (caller != thisAssembly)
{
probablyNotRewritten = caller;
break;
}
}
if (probablyNotRewritten == null)
probablyNotRewritten = thisAssembly;
String simpleName = probablyNotRewritten.GetName().Name;
System.Runtime.CompilerServices.ContractHelper.TriggerFailure(kind, Environment.GetResourceString("MustUseCCRewrite", contractKind, simpleName), null, null, null);
_assertingMustUseRewriter = false;
}
示例5: ContractException
private ContractException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
_Kind = (ContractFailureKind)info.GetInt32("Kind");
_UserMessage = info.GetString("UserMessage");
_Condition = info.GetString("Condition");
}
示例6: ContractFailedEventArgs
public ContractFailedEventArgs(ContractFailureKind failureKind, string message, string condition, Exception originalException)
{
this._failureKind = failureKind;
this._message = message;
this._condition = condition;
this._originalException = originalException;
}
示例7: ContractFailedEventArgs
// internal Exception thrownDuringHandler;
public ContractFailedEventArgs(ContractFailureKind failureKind, String message, String condition, Exception originalException)
{
Contract.Requires(originalException == null || failureKind == ContractFailureKind.PostconditionOnException);
_failureKind = failureKind;
_message = message;
_condition = condition;
_originalException = originalException;
}
示例8: ContractException
internal ContractException (string failure, ContractFailureKind kind, string condition, string userMessage, Exception innerException)
: base (failure, innerException)
{
this.Failure = failure;
this.Kind = kind;
this.Condition = condition;
this.UserMessage = userMessage;
}
示例9: ContractFailedEventArgs
public ContractFailedEventArgs (ContractFailureKind failureKind, string message, string condition, Exception originalException)
{
Condition = condition;
FailureKind = failureKind;
Handled = false;
Unwind = true;
Message = message;
OriginalException = originalException;
}
示例10: ContractFailedEventArgs
public ContractFailedEventArgs (ContractFailureKind failureKind, string message, string condition, Exception originalException)
{
Condition = condition;
FailureKind = failureKind;
Handled = false;
Unwind = false; // MS docs are incorrect - this should default to false.
Message = message;
OriginalException = originalException;
}
示例11: AssertMustUseRewriter
/// <summary>
/// This method is used internally to trigger a failure indicating to the "programmer" that he is using the interface incorrectly.
/// It is NEVER used to indicate failure of actual contracts at runtime.
/// </summary>
static partial void AssertMustUseRewriter(ContractFailureKind kind, String contractKind)
{
if (_assertingMustUseRewriter)
System.Diagnostics.Assert.Fail("Asserting that we must use the rewriter went reentrant.", "Didn't rewrite this mscorlib?");
_assertingMustUseRewriter = true;
// @
Internal.ContractHelper.TriggerFailure(kind, "Must use the rewriter when using Contract." + contractKind, null, null, null);
_assertingMustUseRewriter = false;
}
示例12: GetDisplayMessage
private static string GetDisplayMessage(ContractFailureKind failureKind, string userMessage, string conditionText)
{
string key = null;
switch (failureKind)
{
case ContractFailureKind.Precondition:
key = "PreconditionFailed";
break;
case ContractFailureKind.Postcondition:
key = "PostconditionFailed";
break;
case ContractFailureKind.PostconditionOnException:
key = "PostconditionOnExceptionFailed";
break;
case ContractFailureKind.Invariant:
key = "InvariantFailed";
break;
case ContractFailureKind.Assert:
key = "AssertionFailed";
break;
case ContractFailureKind.Assume:
key = "AssumptionFailed";
break;
default:
Contract.Assume(false, "Unreachable code");
key = "AssumptionFailed";
break;
}
if (!string.IsNullOrEmpty(conditionText))
{
key = key + "_Cnd";
}
string runtimeResourceString = Environment.GetRuntimeResourceString(key);
if (!string.IsNullOrEmpty(conditionText))
{
if (!string.IsNullOrEmpty(userMessage))
{
return (string.Format(CultureInfo.CurrentUICulture, runtimeResourceString, new object[] { conditionText }) + " " + userMessage);
}
return string.Format(CultureInfo.CurrentUICulture, runtimeResourceString, new object[] { conditionText });
}
if (!string.IsNullOrEmpty(userMessage))
{
return (runtimeResourceString + " " + userMessage);
}
return runtimeResourceString;
}
示例13: ContractException
public ContractException(ContractFailureKind kind, string failure, string userMessage, string condition, Exception innerException)
: base(failure, innerException) {
this.m_data._Kind = kind;
this.m_data._UserMessage = userMessage;
this.m_data._Condition = condition;
SerializeObjectState += delegate(object exception, SafeSerializationEventArgs eventArgs) {
// This is fired when the exception is being serialized and asks
// the exception to provide a serializable chunk of state to save
// with the rest of the exception.
eventArgs.AddSerializedState(m_data);
};
}
示例14: RaiseContractFailedEvent
public static string RaiseContractFailedEvent(ContractFailureKind kind, string userMessage, string conditionText, Exception innerException)
{
CountFailure(kind);
#if DEBUG
var kindString = KindToString(kind);
var message = String.Format("{0} failed: {1} {2}", kindString, conditionText, userMessage);
Console.WriteLine(message);
return message;
#else
// handled
return null;
#endif
}
示例15: ReportFailure
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), "failureKind");
Contract.EndContractBlock();
// displayMessage == null means: yes we handled it. Otherwise it is the localized failure message
var displayMessage = Internal.ContractHelper.RaiseContractFailedEvent(failureKind, userMessage, conditionText, innerException);
if (displayMessage == null) return;
Internal.ContractHelper.TriggerFailure(failureKind, displayMessage, userMessage, conditionText, innerException);
}