当前位置: 首页>>代码示例>>C#>>正文


C# ContractFailureKind类代码示例

本文整理汇总了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;
        }
开发者ID:nattress,项目名称:corert,代码行数:40,代码来源:ContractsBCL.cs

示例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;
 }
开发者ID:niemyjski,项目名称:corert,代码行数:7,代码来源:DeveloperExperience.cs

示例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;
 }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:26,代码来源:RuntimeContracts.cs

示例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;
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:28,代码来源:contractsbcl.cs

示例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");
 }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:7,代码来源:ContractException.net40.cs

示例6: ContractFailedEventArgs

 public ContractFailedEventArgs(ContractFailureKind failureKind, string message, string condition, Exception originalException)
 {
     this._failureKind = failureKind;
     this._message = message;
     this._condition = condition;
     this._originalException = originalException;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:ContractFailedEventArgs.cs

示例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;
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:10,代码来源:ContractFailedEventArgs.net35.cs

示例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;
		}
开发者ID:anujb,项目名称:MonoMobile.Facebook,代码行数:8,代码来源:ContractException.cs

示例9: ContractFailedEventArgs

		public ContractFailedEventArgs (ContractFailureKind failureKind, string message, string condition, Exception originalException)
		{
			Condition = condition;
			FailureKind = failureKind;
			Handled = false;
			Unwind = true;
			Message = message;
			OriginalException = originalException;
		}
开发者ID:tgiphil,项目名称:Mono-Class-Libraries,代码行数:9,代码来源:ContractFailedEventArgs.cs

示例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;
		}
开发者ID:carrie901,项目名称:mono,代码行数:9,代码来源:ContractFailedEventArgs.cs

示例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;
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:15,代码来源:ContractsBCL.cs

示例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;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:53,代码来源:ContractHelper.cs

示例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);
   };
 }
开发者ID:nbulp,项目名称:CodeContracts,代码行数:12,代码来源:InternalException.cs

示例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
    }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:13,代码来源:RuntimeContracts.cs

示例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);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:13,代码来源:ContractsBCL.cs


注:本文中的ContractFailureKind类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。