Follow @RoyOsherove on Twitter

Osherove.Interception 1.04 - Change return values and incoming parameter values at runtime easily

I just love the idea of interception. It lets you do stuff like this:

using Osherove.Interception.Framework;

 

namespace Osherove.Interception.Samples.AutoEncryption

{

      public class CryptTestedClass:InterceptableObject

      {

            [EncryptOutput]

            public string GetEncryptedValue(string someValue)

            {

                  //after this line someValue will be automatically

                  //encrypted and returned to the called in its new form

                  return someValue;

            }

 

            [DecryptInput("encrypted")]

            public string ReturnUnEncryptedString (string noChangeableValue,

                                                   string encrypted)

            {

                  //'encrypted' should already be in its unencrypted form in this stage

                  //so we just return it.

                  return encrypted;

            }

      }

}

 


and here are the tests(notice the the encryption example is just a simple string concatenation - for demo purposes.

            [Test]

            public void TestEncrypt()

            {

               CryptTestedClass myClass = new CryptTestedClass();

               string output  = myClass.GetEncryptedValue("SomeValue");

               Assert.AreEqual("SomeValue*SomeEncryptStuffHere*",output);

            }

 

            [Test]

            public void TestDecrypt()

            {

                  string encrypted = "SomeValue*SomeEncryptStuffHere";

                 

                  string decryptedOutput =

                     new CryptTestedClass().

                        ReturnUnEncryptedString("some string",encrypted);

                 

                  Assert.AreEqual("SomeValue",decryptedOutput);

            }
 

If you want to be able to create such a feature, you'll need to download the latest version of my interception framework, version 1.0.4 from here.

OK - back for an evening, leaving tomorrow for a week

See you in three weeks