Created
August 20, 2020 12:00
-
-
Save ShreyasJejurkar/24741edb36ef71b47f4043758144068d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
public static class Program | |
{ | |
public static void Main() | |
{ | |
var movie = new Movie | |
{ | |
Title = "", | |
Length = 5, | |
Year = 1902 | |
}; | |
//false | |
var result = IsValidMovie(movie); | |
var movie2 = new Movie | |
{ | |
Title = "Shreyas", | |
Length = 61, | |
Year = 1923 | |
}; | |
//true | |
var result2 = IsValidMovie(movie2); | |
} | |
/* | |
Using Func to validate the Movie | |
*/ | |
public static bool IsValidMovie(Movie movie) | |
{ | |
Func<Movie, bool>[] rules = | |
{ | |
m => string.IsNullOrWhiteSpace(m.Title), | |
m => m.Length < 60 || m.Length > 400, | |
m => m.Year < 1903 | |
}; | |
return rules.All(rule => rule(movie) == false); | |
} | |
public class Movie | |
{ | |
public string Title { get; set; } | |
public int Length { get; set; } | |
public int Year { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✔️ Compilation completed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 1, | |
"target": "Verify", | |
"mode": "Debug" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment