コード例 #1
0
        private static void TriggerFailureImplementation(ContractFailureKind kind, string displayMessage, string userMessage, string conditionText, Exception innerException)
        {
            if (Environment.IsCLRHosted)
            {
                ContractHelper.TriggerCodeContractEscalationPolicy(kind, displayMessage, conditionText, innerException);
                throw new ContractException(kind, displayMessage, userMessage, conditionText, innerException);
            }
            if (!Environment.UserInteractive)
            {
                throw new ContractException(kind, displayMessage, userMessage, conditionText, innerException);
            }
            string resourceString = Environment.GetResourceString(ContractHelper.GetResourceNameForFailure(kind));

            Assert.Fail(conditionText, displayMessage, resourceString, -2146233022, StackTrace.TraceFormat.Normal, 2);
        }
コード例 #2
0
        private static string GetDisplayMessage(ContractFailureKind failureKind, string userMessage, string conditionText)
        {
            string resourceNameForFailure = ContractHelper.GetResourceNameForFailure(failureKind);
            string resourceString;

            if (!string.IsNullOrEmpty(conditionText))
            {
                resourceString = Environment.GetResourceString(resourceNameForFailure + "_Cnd", (object)conditionText);
            }
            else
            {
                resourceString = Environment.GetResourceString(resourceNameForFailure);
            }
            if (!string.IsNullOrEmpty(userMessage))
            {
                return(resourceString + "  " + userMessage);
            }
            return(resourceString);
        }