internal MalformedDocumentException(MalformedDocumentError error, string path, int line, int position, Exception innerException = null, params object[] additionalArgs)
     : base(FormatMessage(error, path, line, position, null, additionalArgs), innerException)
 {
     _error = error;
     _path = path;
     _line = line;
     _position = position;
 }
 internal MalformedDocumentException(MalformedDocumentError error, string path, int line, int position, Exception innerException = null, params object[] additionalArgs)
     : base(FormatMessage(error, path, line, position, null, additionalArgs), innerException)
 {
     _error    = error;
     _path     = path;
     _line     = line;
     _position = position;
 }
        private static string FormatMessage(MalformedDocumentError error, string path, int line, int position, object value, object[] additionalArgs)
        {
            string message;

            switch (error)
            {
                case MalformedDocumentError.ObjectMissingOpenCurlyBrace:
                    message = "Missing object open curly brace.";
                    break;
                case MalformedDocumentError.ObjectMissingCloseCurlyBrace:
                    message = "Missing object close curly brace.";
                    break;
                case MalformedDocumentError.PropertyNameMissing:
                    message = "Missing property name.";
                    break;
                case MalformedDocumentError.PropertyNameMissingOpenQuote:
                    message = "Missing open quote for property name.";
                    break;
                case MalformedDocumentError.PropertyNameMissingCloseQuote:
                    message = "Missing close quote for property name.";
                    break;
                case MalformedDocumentError.PropertyInvalidName:
                    message = "Invalid property name.";
                    break;
                case MalformedDocumentError.PropertyMissingNameValueSeparator:
                    message = "Missing property name/value separator.";
                    break;
                case MalformedDocumentError.PropertyMissingItemSeparator:
                    message = "Missing property item separator.";
                    break;
                case MalformedDocumentError.ArrayMissingOpenSquareBracket:
                    message = "Missing array open square bracket.";
                    break;
                case MalformedDocumentError.ArrayMissingCommaOrCloseSquareBracket:
                    message = "Missing array comma or close square bracket.";
                    break;
                case MalformedDocumentError.StringMissingOpenQuote:
                    message = "Missing open quote for string value.";
                    break;
                case MalformedDocumentError.StringMissingCloseQuote:
                    message = "Missing close quote for string value.";
                    break;
                case MalformedDocumentError.StringInvalidValue:
                    Debug.Assert(additionalArgs.Length == 1);
                    message = string.Format("Invalid value for '{0}'.", additionalArgs[0]);
                    break;
                case MalformedDocumentError.LiteralInvalidValue:
                    Debug.Assert(additionalArgs.Length == 1);
                    message = string.Format("Invalid literal value, expected '{0}'.", additionalArgs[0]);
                    break;
                case MalformedDocumentError.BooleanInvalidValue:
                    message = "Invalid boolean value.";
                    break;
                case MalformedDocumentError.NumberInvalidValue:
                    Debug.Assert(additionalArgs.Length == 1);
                    message = string.Format("Invalid value for '{0}'.", additionalArgs[0]);
                    break;
                case MalformedDocumentError.MissingValue:
                    message = "Missing value.";
                    break;
                case MalformedDocumentError.InvalidValue:
                    message = "Invalid value.";
                    break;
                case MalformedDocumentError.ExpectedEndOfString:
                    Debug.Assert(additionalArgs.Length == 1);
                    message = string.Format("Expected end of string following legal value, but found '{0}'.", additionalArgs[0]);
                    break;
                case MalformedDocumentError.ExpectedEndOfDecryptedString:
                    Debug.Assert(additionalArgs.Length == 1);
                    message = string.Format("Expected end of decrypted string following legal value, but found '{0}'.", additionalArgs[0]);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("error");
            }

            if (value != null)
            {
                if (value is bool)
                {
                    value = value.ToString().ToLower();
                }
                else if (value is char)
                {
                    value = "'" + value + "'";
                }

                return message + " Path: " + path + ", Value: " + value + ", Line: " + line + ", Position: " + position;
            }

            return message + " Path: " + path + ", Line: " + line + ", Position: " + position;
        }
        private static string FormatMessage(MalformedDocumentError error, string path, int line, int position, object value, object[] additionalArgs)
        {
            string message;

            switch (error)
            {
            case MalformedDocumentError.ObjectMissingOpenCurlyBrace:
                message = "Missing object open curly brace.";
                break;

            case MalformedDocumentError.ObjectMissingCloseCurlyBrace:
                message = "Missing object close curly brace.";
                break;

            case MalformedDocumentError.PropertyNameMissing:
                message = "Missing property name.";
                break;

            case MalformedDocumentError.PropertyNameMissingOpenQuote:
                message = "Missing open quote for property name.";
                break;

            case MalformedDocumentError.PropertyNameMissingCloseQuote:
                message = "Missing close quote for property name.";
                break;

            case MalformedDocumentError.PropertyInvalidName:
                message = "Invalid property name.";
                break;

            case MalformedDocumentError.PropertyMissingNameValueSeparator:
                message = "Missing property name/value separator.";
                break;

            case MalformedDocumentError.PropertyMissingItemSeparator:
                message = "Missing property item separator.";
                break;

            case MalformedDocumentError.ArrayMissingOpenSquareBracket:
                message = "Missing array open square bracket.";
                break;

            case MalformedDocumentError.ArrayMissingCommaOrCloseSquareBracket:
                message = "Missing array comma or close square bracket.";
                break;

            case MalformedDocumentError.StringMissingOpenQuote:
                message = "Missing open quote for string value.";
                break;

            case MalformedDocumentError.StringMissingCloseQuote:
                message = "Missing close quote for string value.";
                break;

            case MalformedDocumentError.StringInvalidValue:
                Debug.Assert(additionalArgs.Length == 1);
                message = string.Format("Invalid value for '{0}'.", additionalArgs[0]);
                break;

            case MalformedDocumentError.LiteralInvalidValue:
                Debug.Assert(additionalArgs.Length == 1);
                message = string.Format("Invalid literal value, expected '{0}'.", additionalArgs[0]);
                break;

            case MalformedDocumentError.BooleanInvalidValue:
                message = "Invalid boolean value.";
                break;

            case MalformedDocumentError.NumberInvalidValue:
                Debug.Assert(additionalArgs.Length == 1);
                message = string.Format("Invalid value for '{0}'.", additionalArgs[0]);
                break;

            case MalformedDocumentError.MissingValue:
                message = "Missing value.";
                break;

            case MalformedDocumentError.InvalidValue:
                message = "Invalid value.";
                break;

            case MalformedDocumentError.ExpectedEndOfString:
                Debug.Assert(additionalArgs.Length == 1);
                message = string.Format("Expected end of string following legal value, but found '{0}'.", additionalArgs[0]);
                break;

            case MalformedDocumentError.ExpectedEndOfDecryptedString:
                Debug.Assert(additionalArgs.Length == 1);
                message = string.Format("Expected end of decrypted string following legal value, but found '{0}'.", additionalArgs[0]);
                break;

            default:
                throw new ArgumentOutOfRangeException("error");
            }

            if (value != null)
            {
                if (value is bool)
                {
                    value = value.ToString().ToLower();
                }
                else if (value is char)
                {
                    value = "'" + value + "'";
                }

                return(message + " Path: " + path + ", Value: " + value + ", Line: " + line + ", Position: " + position);
            }

            return(message + " Path: " + path + ", Line: " + line + ", Position: " + position);
        }