Skip to content

Instantly share code, notes, and snippets.

@ShreyasJejurkar
Created August 20, 2020 12:00
Show Gist options
  • Save ShreyasJejurkar/24741edb36ef71b47f4043758144068d to your computer and use it in GitHub Desktop.
Save ShreyasJejurkar/24741edb36ef71b47f4043758144068d to your computer and use it in GitHub Desktop.
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; }
}
}
✔️ Compilation completed.
{
"version": 1,
"target": "Verify",
"mode": "Debug"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment