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.
Published Tuesday, October 19, 2004 7:52 PM by RoyOsherove
Filed under:

Comments

Tuesday, October 19, 2004 1:59 PM by Derick Bailey

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

fun stuff... spelling mistakes and all. :P

getenCPRYtedvalue
Tuesday, October 19, 2004 5:33 PM by Sam

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

What's "noChangeableValue" for?

And this doesn't look like it couldn't have been done just as easily with the earlier version posted, so spill the beans... what's new? ;)