aop - Postsharp Newbie - Why is args.Instance null? -
new postsharp --- i'm trying out nuget version , i'm trying understand wny in authoriseattribute onentry method agrs.instance value null. i'm trying implement authorsation depends on values of object e.g. customer who's been archived can't have credit limit raised. i'm implementing rules within other classes specific rules.
public class program { static void main(string[] args) { var c = new customer(); c.raisecreditlimit(100000); c.error(00); } } public class customer { [authorizeactivity] public void raisecreditlimit(int newvalue) { } [authorizeactivity] public void error(int newvalue) { } } [serializable] public class authorizeactivityattribute : onmethodboundaryaspect { public override void onentry(methodexecutionargs args) { // //why args.instance null??????????? // if (args.method.name == "raisecreditlimit") { debug.writeline(args.method.name + " started"); } else { throw new exception("crap"); } } public override void onexit(methodexecutionargs args) { debug.writeline(args.method.name + " finished"); } }
the answer because you're not using in aspect. it's optimization. if use in aspect set. change aspect consume instance , there.
public override void onentry(methodexecutionargs args) { // //why args.instance null??????????? // if (args.method.name == "raisecreditlimit") { debug.writeline(args.instance.gettype().name); debug.writeline(args.method.name + " started"); } else { throw new exception("crap"); } }
for more info check out article see else postsharp optimize code http://programmersunlimited.wordpress.com/2011/03/23/postsharp-weaving-community-vs-professional-reasons-to-get-a-professional-license/
Comments
Post a Comment