c# - How to reference properties in an object to reevaluate them every time -
i tried using dictionary map enum
number of bool
properties:
private dictionary<fooenum, bool> isbarbyfoo; private dictionary<fooenum, bool> isbarbyfoo { { return isbarbyfoo ?? (isbarbyfoo = new dictionary<fooenum, bool> { { fooenum.foo1, isbar1 }, { fooenum.foo2, isbar2 }, { fooenum.foo3, isbar3 } }); } } private bool isbar1 => someconditionsthatchangeoverruntime1(); private bool isbar2 => someconditionsthatchangeoverruntime2(); private bool isbar3 => someconditionsthatchangeoverruntime3();
however, approach doesn't work, because properties evaluated once when dictionary created , saved value type - turns out misunderstood way properties work.
is possible store properties in dictionary in way evaluates them every time they're looked up, or can suggest different solution kind of problem?
another solution may forget dictionary , use method value:
private bool getisbarbyfoo(fooenum foo) { switch (foo) { case fooenum.foo1: return someconditionsthatchangeoverruntime1(); case fooenum.foo2: return someconditionsthatchangeoverruntime2(); case fooenum.foo3: return someconditionsthatchangeoverruntime3(); default: return false; } }
Comments
Post a Comment