Working at the MetaData Level

In most projects though (at least in some I've recently heard of) there is a direct proportionality between days to deadline and quality of documentation. Somehow people tend to forget to update comments as soon as their boss is reminding them that they should have shipped it yesterday.

Wouldn't it be great to just specify those checks using some source code attributes and have some "black magic" happen between the client and your objects that takes care of checking the passed values against those attributes?

In a perfect world, these methods might simply look like this:

 public String Name {    [Check(MaxLength=30)]    set    {       _name = value;    }    get    {       return _name;    } } public void Donate([Check(MaxValue=100)] double amount) {    _totalDonation = _totalDonation + amount; } 

Now the documentation of your business logic is applied on the metadata level! You could easily use reflection to generate printed or online documentation that includes these basic business logic checks as well.

Well, unfortunately, no checks have been done yet. In fact, when using this class, you could easily set Name to any possible value and Donate() to whatever amount you'd like.


You're now really about to read about unsupported and undocumented features of .NET Framework.Your mileage may vary.

What's still missing is that magic something I mentioned that would sit between the client and your object (running maybe within the same process and application) and perform those checks. This is where ContextBoundObject enters the game.

Advanced  .NET Remoting C# Edition
Advanced .NET Remoting (C# Edition)
ISBN: 1590590252
EAN: 2147483647
Year: 2002
Pages: 91
Authors: Ingo Rammer © 2008-2017.
If you may any questions please contact us: