Using a ref Parameter with the this Keyword?

Posted by grefly on Stack Overflow See other posts from Stack Overflow or by grefly
Published on 2010-04-15T16:13:25Z Indexed on 2010/04/15 16:23 UTC
Read the original article Hit count: 269

Filed under:
|
|

Is there a way to force the this keyword to act as a ref argument? I would like to pass in a visitor that modifies multiple properties on the object, but this only wants to act like a value parameter.

Code in Object:

public void Accept(Visitor<MyObject> visitor)
{
    visitor.Visit(this);
}

Code in Visitor:

public void Visit(ref Visitor<MyObject> receiver)
{
    receiver.Property = new PropertyValue();
    receiver.Property2 = new PropertyValue();
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about ref