//public static string ErrorForIncompatibleEnsuresAndReturnType(IType methodResult, IDeclaredType contractResult,
        //    ICSharpFunctionDeclaration method)
        //{
        //    string kind = "method";
        //    string name = method.DeclaredName;

        //    var property = method as IAccessorDeclaration;
        //    if (property != null)
        //    {
        //        kind = "property";
        //        name = name.Replace("get_", "");
        //    }

        //    return string.Format("Detected a call to Result with '{0}' in {1} '{2}', should be '{3}'",
        //        contractResult.GetPresentableName(CSharpLanguage.Instance), kind, name,
        //        methodResult.GetPresentableName(CSharpLanguage.Instance));
        //}

        public static string GetErrorText(this MalformedContractCustomWarning warning, string contractMethodName)
        {
            switch (warning)
            {
            case MalformedContractCustomWarning.PreconditionInAsyncMethod:
                return(string.Format("Lecacy precondition in async method is asynchronous and will fail returning task"));

            case MalformedContractCustomWarning.PreconditionInMethodWithIteratorBlock:
                return(string.Format("Legacy precondition in iterator block will throw only on first MoveNext() call"));

            default:
                Contract.Assert(false, "Unknown custom warning: " + warning);
                throw new InvalidOperationException("Unknown custom warning: " + warning);
            }
        }
예제 #2
0
 public CustomWarningValidationResult(ICSharpStatement statement,
                                      MalformedContractCustomWarning customWarning)
     : base(statement)
 {
     _customWarning = customWarning;
 }
예제 #3
0
 public static ValidationResult CreateCustomWarning(ICSharpStatement statement,
                                                    MalformedContractCustomWarning customWarning)
 {
     return(new CustomWarningValidationResult(statement, customWarning));
 }