• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ContractFailureKind类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ContractFailureKind的典型用法代码示例。如果您正苦于以下问题:C# ContractFailureKind类的具体用法?C# ContractFailureKind怎么用?C# ContractFailureKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ContractFailureKind类属于命名空间,在下文中一共展示了ContractFailureKind类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: AssertException

        private void AssertException(Action block, ContractFailureKind expectedKind, string expectedMessage, string expectedUserMessage, Exception expectedInnerException)
        {
            try
            {
                block();
            }
            catch (Exception ex)
            {
                var cex = ex as ContractException;
                if (cex == null)
                    Assert.Fail("Unexpected Exception");

                Assert.True(cex.Kind == expectedKind, "Kind");
                Assert.True(cex.Message == expectedMessage, "Message");
                Assert.True(cex.UserMessage == expectedUserMessage, "UserMessage");
                if (cex.InnerException != null)
                    Assert.True(cex.InnerException.Equals(expectedInnerException), "InnerException");
                else if (cex.InnerException == null && expectedInnerException != null)
                    Assert.Fail("InnerException");
            }
        }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:21,代码来源:ContractTests.cs


示例17: CheckAllMessages

		private void CheckAllMessages (ContractFailureKind kind, string messageStart, Action<string, Exception, string, ContractFailureKind, Func<string>> fnAssert)
		{

			foreach (Exception ex in new [] { null, new ArgumentNullException () }) {
				fnAssert (messageStart + ".", ex, null, kind, () => {
					return ContractHelper.RaiseContractFailedEvent (kind, null, null, ex);
				});

				fnAssert (messageStart + ".  Message", ex, null, kind, () => {
					return ContractHelper.RaiseContractFailedEvent (kind, "Message", null, ex);
				});

				fnAssert (messageStart + ": Condition", ex, "Condition", kind, () => {
					return ContractHelper.RaiseContractFailedEvent (kind, null, "Condition", ex);
				});

				fnAssert (messageStart + ": Condition  Message", ex, "Condition", kind, () => {
					return ContractHelper.RaiseContractFailedEvent (kind, "Message", "Condition", ex);
				});
			}

		}
开发者ID:nlhepler,项目名称:mono,代码行数:22,代码来源:ContractHelperTest.cs


示例18: RaiseContractFailedEvent

		public static string RaiseContractFailedEvent (ContractFailureKind failureKind, string userMessage, string conditionText, Exception innerException)
		{

			StringBuilder msg = new StringBuilder (60);
			switch (failureKind) {
			case ContractFailureKind.Assert:
				msg.Append ("Assertion failed");
				break;
			case ContractFailureKind.Assume:
				msg.Append ("Assumption failed");
				break;
			case ContractFailureKind.Invariant:
				msg.Append ("Invariant failed");
				break;
			case ContractFailureKind.Postcondition:
				msg.Append ("Postcondition failed");
				break;
			case ContractFailureKind.PostconditionOnException:
				msg.Append ("Postcondition failed after throwing an exception");
				break;
			case ContractFailureKind.Precondition:
				msg.Append ("Precondition failed");
				break;
			default:
				throw new NotSupportedException ("Not supported: " + failureKind);
			}
			if (conditionText != null) {
				msg.Append (": ");
				msg.Append (conditionText);
			} else {
				msg.Append ('.');
			}
			if (userMessage != null) {
				msg.Append ("  ");
				msg.Append (userMessage);
			}
			string msgString = msg.ToString ();

			Exception handlerException = null;
			bool unwind = false, handled = false;

			var contractFailed = Contract.InternalContractFailedEvent;
			if (contractFailed != null) {
				// Execute all event handlers
				var handlers = contractFailed.GetInvocationList ();
				var e = new ContractFailedEventArgs (failureKind, msgString, conditionText, innerException);
				foreach (var handler in handlers) {
					try {
						handler.DynamicInvoke (null, e);
					} catch (Exception ex) {
						e.SetUnwind ();
						// If multiple handlers throw an exception then the specification states that it
						// is undetermined which one becomes the InnerException.
						handlerException = ex.InnerException;
					}
				}
				unwind = e.Unwind;
				handled = e.Handled;
			}

			if (unwind) {
				Exception ex = innerException ?? handlerException;
				throw new ContractException (msgString, failureKind, conditionText, userMessage, ex);
			}

			return handled ? null : msgString;
		}
开发者ID:ngraziano,项目名称:mono,代码行数:67,代码来源:ContractHelper.cs


示例19: TriggerFailure

		public static void TriggerFailure (ContractFailureKind kind, string displayMessage, string userMessage, string conditionText, Exception innerException)
		{
			StringBuilder msg = new StringBuilder (50);

			if (conditionText != null) {
				msg.Append ("Expression: ");
				msg.AppendLine (conditionText);
			}
			msg.Append ("Description: ");
			if (displayMessage != null) {
				msg.Append (displayMessage);
			}
#if MOONLIGHT
			// Silverlight shows a dialog that let you Abort (kill process/browser), Retry or Ignore
			// Moonlight will simply warn and ignore (at least until FailFast is implemented)
			// using reflection into System.Windows.Browser to popup an browser alert
			alert.Invoke (window, new object [] { msg.ToString () });
#else
			if (Environment.UserInteractive) {
				// FIXME: This should trigger an assertion.
				// But code will never get here at the moment, as Environment.UserInteractive currently
				// always returns false.
				throw new ContractShouldAssertException (msg.ToString ());
			} else {
				// Note that FailFast() currently throws a NotImplementedException()
				Environment.FailFast(msg.ToString()/*, new ExecutionEngineException()*/);
			}
#endif
		}
开发者ID:ngraziano,项目名称:mono,代码行数:29,代码来源:ContractHelper.cs


示例20: ContractException

 public ContractException(ContractFailureKind kind, string failure, string userMessage, string condition, Exception innerException) : base(failure, innerException)
 {
     this._Kind = kind;
     this._UserMessage = userMessage;
     this._Condition = condition;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:6,代码来源:ContractException.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Contracts类代码示例发布时间:2022-05-24
下一篇:
C# Contract类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap