public override bool IsValid(string folderPath, out ITypeErrorBuilder typeError) { if (!string.IsNullOrEmpty(folderPath) && folderPath.IndexOfAny(InvalidRelativeFolderChars) < 0 && !Path.IsPathRooted(folderPath)) { try { var localApplicationFolder = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)); var subFolder = new DirectoryInfo(Path.Combine(localApplicationFolder.FullName, folderPath)); for (var parentFolder = subFolder.Parent; parentFolder != null; parentFolder = parentFolder.Parent) { // Indeed a subfolder? if (localApplicationFolder.FullName == parentFolder.FullName) { return(ValidValue(out typeError)); } } } catch { // For all kinds of DirectoryInfo exceptions not prevented by the if-statement, // just return InvalidValue(). } } return(InvalidValue(SubFolderNameTypeError, out typeError)); }
private ValueTypeErrorAtPropertyKey( ITypeErrorBuilder typeErrorBuilder, string propertyKey, string actualValueString, int start, int length) : base(typeErrorBuilder, actualValueString, start, length) { PropertyKey = propertyKey; }
private ValueTypeErrorAtItemIndex( ITypeErrorBuilder typeErrorBuilder, int itemIndex, string actualValueString, int start, int length) : base(typeErrorBuilder, actualValueString, start, length) { ItemIndex = itemIndex; }
/// <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)); }
internal override Union <ITypeErrorBuilder, PValue> TryCreateFromMap( string json, GreenJsonMapSyntax jsonMapSyntax, out SettingObject convertedValue, int mapSyntaxStartPosition, List <JsonErrorInfo> errors) { var mapBuilder = new Dictionary <string, PValue>(); // Analyze values with this schema while building the PMap. foreach (var(keyNodeStart, keyNode, valueNodeStart, valueNode) in jsonMapSyntax.ValidKeyValuePairs()) { if (TryGetProperty(new SettingKey(keyNode.Value), out SettingProperty property)) { var valueOrError = property.TryCreateValue( json, valueNode, mapSyntaxStartPosition + valueNodeStart, errors); if (valueOrError.IsOption2(out PValue convertedItemValue)) { mapBuilder.Add(keyNode.Value, convertedItemValue); } else { ITypeErrorBuilder typeError = valueOrError.ToOption1(); errors.Add(ValueTypeErrorAtPropertyKey.Create( typeError, keyNode, valueNode, json, mapSyntaxStartPosition + keyNodeStart, mapSyntaxStartPosition + valueNodeStart)); } } else { errors.Add(UnrecognizedPropertyKeyTypeError.Create( keyNode, json, mapSyntaxStartPosition + keyNodeStart)); } } var map = new PMap(mapBuilder); convertedValue = new SettingObject(this, map); return(map); }
internal ValueTypeError(ITypeErrorBuilder typeErrorBuilder, string actualValueString, int start, int length) : base(start, length) { TypeErrorBuilder = typeErrorBuilder; ActualValueString = actualValueString; }
public override bool IsValid(PInteger candidateValue, out ITypeErrorBuilder typeError) => MinValue <= candidateValue.Value && candidateValue.Value <= MaxValue ? ValidValue(out typeError) : InvalidValue(this, out typeError);
/// <summary> /// Returns if a value of the target type is a member of this <see cref="PType"/>. /// </summary> /// <param name="candidateValue"> /// The candidate value to check. /// </param> /// <param name="typeError"> /// A type error, if the candidate value is invalid. /// </param> /// <returns> /// True if the candidate value is valid; otherwise false. /// </returns> public abstract bool IsValid(T candidateValue, out ITypeErrorBuilder typeError);
/// <summary> /// Helper method to indicate a successful conversion in <see cref="IsValid(T, out ITypeErrorBuilder)"/>. /// </summary> /// <param name="typeError"> /// Always returns null. /// </param> /// <returns> /// Always returns true. /// </returns> protected bool ValidValue(out ITypeErrorBuilder typeError) { typeError = null; return(true); }
/// <summary> /// Helper method to indicate a failed conversion in <see cref="IsValid(T, out ITypeErrorBuilder)"/>. /// </summary> /// <param name="convertTypeError"> /// The type error generated by the failed conversion. /// </param> /// <param name="typeError"> /// Always returns <paramref name="convertTypeError"/>. /// </param> /// <returns> /// Always returns false. /// </returns> protected bool InvalidValue(ITypeErrorBuilder convertTypeError, out ITypeErrorBuilder typeError) { typeError = convertTypeError; return(false); }