0

When I set a property of a moled type, it looks like they always require, as the first parameter, an object of the original moled type. I also noticed that some of the examples in the Moles Reference Guide assign this parameter as @this and I am trying to figure out why.

For instance, the original class looks something like this:

public class ProductDAO
{
    internal void Insert(Product product, string id)
    {
        ...
    }
}

When I go to mole this method, the property is expecting a delegate whose first parameter is always the type of the moled object, in this case, a ProductDAO object. So in this case, the property is expecting a delegate of:

Action<ProductDAO, Product, string>

So do I always have to provide that moled object as the first parameter of my lambda expression? If so, what's the difference in using a regular variable name versus @this? What does @this mean/do?

MProductDAO.AllInstances.InsertProductString = (dao, product, id) => { };

versus

MProductDAO.AllInstances.InsertProductString = (@this, product, id) => { };
sth
  • 222,467
  • 53
  • 283
  • 367
Cindy K.
  • 128
  • 2
  • 10
  • 1
    Have a look here: [What's the use/meaning of the @ character in variable names in C#?](http://stackoverflow.com/questions/91817/whats-the-use-meaning-of-the-character-in-variable-names-in-c) – Jay Riggs Jul 20 '11 at 22:53
  • From how you described it, this reminds me a lot of the syntax of VB. For example, in VB you can call the app name through the code, but it normally asks the use of something around the lines of "me.label...etc" – Jason Jul 20 '11 at 23:00
  • @Jay - Thanks! That helped a lot! So from what I gather, they are really the same - both just a variable declaration - but the _@this_ is more clear to the reader that the first parameter is referencing the calling object instance. I like it! – Cindy K. Jul 21 '11 at 17:13

0 Answers0