File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -318,24 +318,19 @@ public partial class PhoneRule(string? customMessage = null) : IValidatorRule<st
318318/// </summary>
319319/// <param name="mustExist">If true, validates that the file actually exists on the file system. Defaults to false.</param>
320320/// <param name="customMessage">An optional custom error message. If not provided, a default message is used.</param>
321+ /// <exception cref="ArgumentException">Thrown when the file path is invalid.</exception>
321322public class FilePathRule ( bool mustExist = false , string ? customMessage = null )
322- : IValidatorRule < string >
323+ : RulesBase < string > ( BuildPredicate ( mustExist ) , BuildMessage ( mustExist ) , customMessage )
323324{
324- /// <inheritdoc/>
325- public bool IsValid ( string value )
325+ private static Func < string , bool > BuildPredicate ( bool mustExist )
326326 {
327- try
327+ return value =>
328328 {
329329 string fullPath = Path . GetFullPath ( value ) ;
330330 return ! mustExist || File . Exists ( fullPath ) ;
331- }
332- catch
333- {
334- return false ;
335- }
331+ } ;
336332 }
337333
338- /// <inheritdoc/>
339- public string ErrorMessage { get ; } =
340- customMessage ?? ( mustExist ? "File path must exist" : "Input must be a valid file path" ) ;
334+ private static string BuildMessage ( bool mustExist ) =>
335+ mustExist ? "File path must exist" : "Input must be a valid file path" ;
341336}
You can’t perform that action at this time.
0 commit comments