using System.Linq.Expressions;
using System.Collections.Generic;
public enum DroitsHomonymes
public class FormHomonymeModel
private Dictionary<string, DroitsHomonymes> _listeDesDroits { get; set; }
public DroitsHomonymes DonneDroits<T>(Expression<Func<T>> propertyLambda) {
var me = propertyLambda.Body as MemberExpression;
throw new ArgumentException("You must pass a lambda of the form: '() => Class.Property' or '() => object.Property'");
string attribut = me.Member.Name;
if (_listeDesDroits.ContainsKey(attribut) == true)
return _listeDesDroits[attribut];
return DroitsHomonymes.FacultatifDecoche;
public void MetAJourDroits<T>(Expression<Func<T>> propertyLambda, DroitsHomonymes droit) {
var me = propertyLambda.Body as MemberExpression;
throw new ArgumentException("You must pass a lambda of the form: '() => Class.Property' or '() => object.Property'");
if (_listeDesDroits == null)
_listeDesDroits = new Dictionary<string, DroitsHomonymes>();
_listeDesDroits.Add(me.Member.Name, droit);
public bool rechercheStricte { get; set; }
public bool Patients { get; set; }
public bool Entourage { get; set; }
public bool Assures { get; set; }
public bool Personnels { get; set; }
public bool Intervenants { get; set; }
public bool Autres { get; set; }
public static void Main()
FormHomonymeModel f = new FormHomonymeModel();
Console.WriteLine("-- Ecriture des droits --\n");
f.MetAJourDroits(() => f.rechercheStricte, DroitsHomonymes.FacultatifCoche);
f.MetAJourDroits(() => f.Patients, DroitsHomonymes.Obligatoire);
f.MetAJourDroits(() => f.Assures, DroitsHomonymes.Interdit);
Console.WriteLine("-- Lecture des droits --\n");
Console.WriteLine(string.Format("recherche stricte : {0}", f.DonneDroits(() => f.rechercheStricte)));
Console.WriteLine(string.Format("Assurés : {0}", f.DonneDroits(() => f.Assures)));
Console.WriteLine(string.Format("Patients : {0}", f.DonneDroits(() => f.Patients)));
Console.WriteLine(string.Format("Autres : {0}", f.DonneDroits(() => f.Autres)));