c# - Alternative of Aspect Oriented Programming -
is there alternative of using aspect oriented programming inject repetitive code. suppose have class contains many properties , if property value changed log that.
class person { public string name { get{return name;} set { name = value; logpropertychanged("name"); } } public int age { get{return age;} set { age = value; logpropertychanged("age"); } } }
how rid of repetitive code security checking, logging , stuff without using aspect oriented programming.
you can this
a) on parent class of objects
protected void setproperty<t>(expression<func<t>> exp, t value) { memberexpression body = (memberexpression)exp.body; //set actual value (body.member fieldinfo).setvalue(this, value); //do logging, locking, etc. field name string fieldname = body.member.name; }
b) on objects
private int age; public int age { { return age; } set { setproperty(() => age, value); } }
Comments
Post a Comment