/// <summary> /// Initializes a new instance of <see cref="ValueTypeError"/>. /// </summary> /// <param name="typeErrorBuilder"> /// The context insensitive information for this error message. /// </param> /// <param name="valueNode"> /// The value node corresponding to the value that was typechecked. /// </param> /// <param name="json"> /// The source json which contains the type error. /// </param> /// <param name="valueNodeStart"> /// The start position of the value node in the source json. /// </param> /// <returns> /// A <see cref="ValueTypeError"/> instance which generates a localized error message. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="typeErrorBuilder"/> and/or <paramref name="valueNode"/> and/or <paramref name="json"/> are null. /// </exception> public static ValueTypeError Create(ITypeErrorBuilder typeErrorBuilder, GreenJsonValueSyntax valueNode, string json, int valueNodeStart) { if (typeErrorBuilder == null) { throw new ArgumentNullException(nameof(typeErrorBuilder)); } return(new ValueTypeError( typeErrorBuilder, PTypeErrorBuilder.GetValueDisplayString(valueNode, json, valueNodeStart), valueNodeStart, valueNode.Length)); }
private string GenericTypeErrorMessage(Localizer localizer, string actualValueString, Maybe <string> maybeSomewhere) { if (stringToTarget.Count == 0) { return(maybeSomewhere.Match( whenNothing: () => localizer.Localize( PTypeErrorBuilder.NoLegalValuesError, actualValueString), whenJust: somewhere => localizer.Localize( PTypeErrorBuilder.NoLegalValuesErrorSomewhere, actualValueString, somewhere))); } string localizedKeysList; if (stringToTarget.Count == 1) { localizedKeysList = PTypeErrorBuilder.QuoteStringValue(stringToTarget.Keys.First()); } else { // TODO: escape characters in KeyedSet keys. IEnumerable <string> keys = stringToTarget.Keys.Take(stringToTarget.Count - 1).Select(PTypeErrorBuilder.QuoteStringValue); var lastKey = PTypeErrorBuilder.QuoteStringValue(stringToTarget.Keys.Last()); localizedKeysList = localizer.Localize( PTypeErrorBuilder.EnumerateWithOr, string.Join(", ", keys), lastKey); } return(maybeSomewhere.Match( whenNothing: () => PTypeErrorBuilder.GetLocalizedTypeErrorMessage( localizer, localizedKeysList, actualValueString), whenJust: somewhere => PTypeErrorBuilder.GetLocalizedTypeErrorSomewhereMessage( localizer, localizedKeysList, actualValueString, somewhere))); }
private string GenericTypeErrorMessage(Localizer localizer, string actualValueString, Maybe <string> maybeSomewhere) { if (stringToEnum.Count == 0) { return(maybeSomewhere.Match( whenNothing: () => localizer.Localize( PTypeErrorBuilder.NoLegalValuesError, actualValueString), whenJust: somewhere => localizer.Localize( PTypeErrorBuilder.NoLegalValuesErrorSomewhere, actualValueString, somewhere))); } string localizedValueList; if (stringToEnum.Count == 1) { localizedValueList = PTypeErrorBuilder.QuoteStringValue(stringToEnum.Keys.First()); } else { IEnumerable <string> enumValues = stringToEnum.Keys.Take(stringToEnum.Count - 1).Select(PTypeErrorBuilder.QuoteStringValue); var lastEnumValue = PTypeErrorBuilder.QuoteStringValue(stringToEnum.Keys.Last()); localizedValueList = localizer.Localize( PTypeErrorBuilder.EnumerateWithOr, string.Join(", ", enumValues), lastEnumValue); } return(maybeSomewhere.Match( whenNothing: () => PTypeErrorBuilder.GetLocalizedTypeErrorMessage( localizer, localizedValueList, actualValueString), whenJust: somewhere => PTypeErrorBuilder.GetLocalizedTypeErrorSomewhereMessage( localizer, localizedValueList, actualValueString, somewhere))); }
public string GetLocalizedTypeErrorAtItemIndexMessage(Localizer localizer, string actualValueString, int itemIndex) => GenericTypeErrorMessage(localizer, actualValueString, PTypeErrorBuilder.GetLocatedAtItemIndexMessage(localizer, itemIndex));
public string GetLocalizedTypeErrorAtPropertyKeyMessage(Localizer localizer, string actualValueString, string propertyKey) => GenericTypeErrorMessage(localizer, actualValueString, PTypeErrorBuilder.GetLocatedAtPropertyKeyMessage(localizer, propertyKey));
/// <summary> /// Initializes a new instance of <see cref="UnrecognizedPropertyKeyTypeError"/>. /// </summary> /// <param name="keyNode"> /// The property key for which the error is generated. /// </param> /// <param name="json"> /// The source json which contains the type error. /// </param> /// <param name="keyNodeStart"> /// The start position of the key node in the source json. /// </param> /// <returns> /// A <see cref="UnrecognizedPropertyKeyTypeError"/> instance which generates a localized error message. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="keyNode"/> and/or <paramref name="json"/> are null. /// </exception> public static UnrecognizedPropertyKeyTypeError Create(GreenJsonStringLiteralSyntax keyNode, string json, int keyNodeStart) => new UnrecognizedPropertyKeyTypeError( PTypeErrorBuilder.GetPropertyKeyDisplayString(keyNode, json, keyNodeStart), keyNodeStart, keyNode.Length);
public BaseType(LocalizedStringKey expectedTypeDescriptionKey, GreenJsonValueSyntaxVisitor <Maybe <TValue> > converter) { typeError = new PTypeErrorBuilder(expectedTypeDescriptionKey); this.converter = converter; }