vc3/Afterthought — Issue #29: Method body inspection
Author: DamianReeves
Created: 2011-11-11 16:51:48+00:00
State: open

Is it possible to provide a mechanism for checking for the body of a method/property either being empty or just throws an exception. I would like to provide an adapter mechanism, but I don't want to go attribute crazy with marking methods and properties for exclusion.

Here's an example:

````C#
[InheritedExport]
public interface IStrategy {
void Method1();
void Method2();
//... Lots more methods
void Method20();
}

//Matches IStrategy signature but does not implement IStrategy
internal class HiddenOrExternalStrategy {
public void Method1() {}
public void Method2() {}
//... Lots more methods
public void Method19() {}
}

[Export(typeof(IStrategy))]
public class PublicStrategy: IStrategy {
IStrategy _adapted;
internal PublicStrategy(HiddenOrExternalStrategy) {
}

public void Method1() {}
public void Method1() {
throw new NotImplementedException();
}
public void Method20() {
//Doing something special so not adapted
_adapted.Method1();
_adapted.Method19();
}
}
````
Now I know you might be thinking, why not just use Afterthought to amend `HiddenOrExternalStrategy` so that we skip all the extra mess, but the point is I want consumers of my API to never know about or be able to bind directly to `HiddenOrExternalStrategy` because for example I might at a later time use `HiddenOrExternalStrategy2` or `SuperSecretStrategy` in its place.

Now I know I could go around decorating methods with some custom `[NotImplementedAttribute]`, but it could become tedious doing this for all the methods (imagine doing this for 100s of methods). So knowing this is a fallback method is there anything that can be done to inspect a method body?