{
public string Title { get; set; }
public int ReleaseYear { get; set; }
public int Length { get; set; }
}
public static class MovieValidator
{
public static bool IsValid1(Movie movie)
{
if (movie.Title.IsNullOrWhiteSpace()) return false;
if (movie.ReleaseYear < 1900) return false;
if (movie.Length <= 0) return false;
return true;
}
public static bool IsValid2(Movie movie)
{
Func
{
m => m.Title.IsNotNullOrWhiteSpace(),
m => m.Length > 0,
m => m.ReleaseYear > 1900
};
return rules.All(rule => rule(movie));
}
public static bool IsNullOrWhiteSpace(this string value)
{
return string.IsNullOrEmpty(value) || value.Length.Equals(0);
}
public static bool IsNotNullOrWhiteSpace(this string value)
{
return !value.IsNullOrWhiteSpace();
}
}
No comments:
Post a Comment