using System.Collections;
using System.Collections.Generic;
public static void Main()
var p1 = new Persoon(18,"Piet","Klaassen");
public int Leeftijd {get;set;}
public string Achternaam {get;set;}
public string Voornaam {get;set;}
public Persoon(int Leeftijd, string Voornaam, string Achternaam){
Leeftijd.ThrowIfLessThan("Persoon->Leeftijd minimaal 18", 18);
Leeftijd.ThrowIfNotBetween("Oeps dit getal is niet tussen 18 en 30", 18,30);
Voornaam.ThrowIfEmpty("Persoon->Voornaam");
Achternaam.ThrowIfEmpty("Persoon->Achternaam");
public static class ValidationExtensions
public static void ThrowIfLessThan(this int e, string Message, int Value = 0)
throw new Exception(Message);
public static void ThrowIfNotBetween(this int e, string Message, int From, int To)
throw new Exception(Message);
public static void ThrowIfNullOrZero(this int? e, string Message)
if (e == null || e.Value == 0)
throw new Exception(Message);
public static void ThrowIfEmpty(this object e, string Message)
throw new ArgumentNullException(Message);
public static void ThrowIfSame(this object e, object Other, string Message)
throw new Exception(Message);