Uncatchable ChuckNorrisException

I haven’t tried this, so I don’t know if the JVM would restrict something like this, but maybe you could compile code which throws ChuckNorrisException, but at runtime provide a class definition of ChuckNorrisException which does not extend Throwable. UPDATE: It doesn’t work. It generates a verifier error: Exception in thread “main” java.lang.VerifyError: (class: TestThrow, … Read more

Traditional logging vs AOP logging

For performance, AOP approach certainly has a little overhead against the traditional one. One of the many strengths of AOP is that it allows you to separate your non-business concerns from your business logic. It also helps you in mundane tasks such putting a logging logic in each of your method or place a try-catch … Read more

Is there any attribute relating to AJAX to be set for ASP.NET MVC controller actions?

I don’t think there is built in attribute for ajax, but you can create your own AjaxOnly filter like this: public class AjaxOnlyAttribute : ActionMethodSelectorAttribute { public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo) { return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest(); } } And decorate your action methods like this: [AjaxOnly] public ActionResult AjaxMethod() { } See Also: ASP.NET MVC … Read more

execution Vs. call Join point

Acutally the explanation is quite simple if you understand the basic difference between call() and execution() pointcuts: While the former intercepts all callers (i.e. the sources of method calls), the latter intercepts the calls themselves no matter where they originate from. So how can the number of interceptions triggered by both pointcuts differ? If you … Read more

Aspect Oriented Programming in C# [closed]

Just to get your head around it: It is the ability to hook events such as: creation of objects, setting of properties, etc, and attach general functions to them, that will be populated with relevant context. Because C# doesn’t have an inbuilt facility for this, you need a framework, like PostSharp, to do ‘bytecode weaving’ … Read more

WCF service attribute to log method calls and exceptions

Yes, it is possible to encapsulate this kind of logging, using the extensibility points built into WCF. There are actually multiple possible approaches. The one I’m describing here adds an IServiceBehavior, which uses a custom IOperationInvoker, and does not require any web.config modifications. There are three parts to this. Create an implementation of IOperationInvoker, which … Read more

How to inject an attribute using a PostSharp attribute?

See http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-12-e28093-Aspect-Providers-e28093-Part-1.aspx Here is a working example. Applying this aspect to a class will apply the XmlIgnore attribute to any public property that does not already have XmlElement or XmlAttribute applied to it. the trick is using the CustomAttributeIntroductioinAspect that is built in to Postsharp. You just need to instantiate an instance specifying the attribute … Read more