Example #1
0
        /// <summary>
        /// Return invocation failure for cases outside the execution of contract code.
        /// </summary>
        public static ContractInvocationResult Failure(ContractInvocationErrorType errorType)
        {
            switch (errorType)
            {
            case ContractInvocationErrorType.MethodDoesNotExist:
                return(new ContractInvocationResult(errorType, new ContractErrorMessage("Method does not exist on contract.")));

            case ContractInvocationErrorType.MethodIsConstructor:
                return(new ContractInvocationResult(errorType, new ContractErrorMessage("Attempted to invoke constructor on existing contract.")));

            case ContractInvocationErrorType.MethodIsPrivate:
                return(new ContractInvocationResult(errorType, new ContractErrorMessage("Attempted to invoke private method.")));

            case ContractInvocationErrorType.ParameterCountIncorrect:
                return(new ContractInvocationResult(errorType, new ContractErrorMessage("Incorrect number of parameters passed to method.")));

            case ContractInvocationErrorType.ParameterTypesDontMatch:
                return(new ContractInvocationResult(errorType, new ContractErrorMessage("Parameters sent don't match expected method parameters.")));

            default:
                throw new NotSupportedException($"Should use either {nameof(Success)} or {nameof(ExecutionFailure)} for this ContractInvocationErrorType.");
            }
        }
        private static string GetErrorMessage(ContractInvocationErrorType errorType)
        {
            switch (errorType)
            {
            case ContractInvocationErrorType.MethodDoesNotExist:
                return(ContractInvocationErrors.MethodDoesNotExist);

            case ContractInvocationErrorType.MethodIsConstructor:
                return(ContractInvocationErrors.MethodIsConstructor);

            case ContractInvocationErrorType.MethodIsPrivate:
                return(ContractInvocationErrors.MethodIsPrivate);

            case ContractInvocationErrorType.ParameterCountIncorrect:
                return(ContractInvocationErrors.ParameterCountIncorrect);

            case ContractInvocationErrorType.ParameterTypesDontMatch:
                return(ContractInvocationErrors.ParameterTypesDontMatch);

            default:
                throw new NotSupportedException($"Should use either {nameof(Success)} or {nameof(ExecutionFailure)} for this ContractInvocationErrorType.");
            }
        }
Example #3
0
 public static ContractInvocationResult Failure(ContractInvocationErrorType errorType, Exception exception)
 {
     return(new ContractInvocationResult(errorType));
 }
Example #4
0
 private ContractInvocationResult(ContractInvocationErrorType errorType, Exception exception)
 {
     this.IsSuccess           = false;
     this.InvocationErrorType = errorType;
     this.Exception           = exception;
 }
Example #5
0
 private ContractInvocationResult(ContractInvocationErrorType errorType)
 {
     this.IsSuccess           = false;
     this.InvocationErrorType = errorType;
 }
Example #6
0
 /// <summary>
 /// Return invocation failure for cases related to execution inside contract code.
 /// </summary>
 public static ContractInvocationResult ExecutionFailure(ContractInvocationErrorType errorType, Exception exception)
 {
     return(new ContractInvocationResult(errorType, new ContractErrorMessage(exception.ToString())));
 }
        /// <summary>
        /// Return invocation failure for cases outside the execution of contract code.
        /// </summary>
        public static ContractInvocationResult Failure(ContractInvocationErrorType errorType)
        {
            string errorMessage = GetErrorMessage(errorType);

            return(new ContractInvocationResult(errorType, new ContractErrorMessage(errorMessage)));
        }