It sounds like you got an answer to your larger question already. But let's consider this one anyway.
Is there a way to force the this keyword to act as a ref argument?
Yes. Work it through logically.
- A ref argument makes an alias for a variable.
- "this" is not a variable in a reference type
- "this" is a variable in a value type
- therefore the only way to pass a "ref this" is from an instance method of a value type.
And in fact that is how "this" is implemented in a value type behind the scenes. When you have a (worst practice! do not actually do this) mutable value type:
struct S
{
private int x;
public void M()
{
this.x = 123;
}
}
...
S s = new S();
s.M();
Since instances of S are passed by value how is it that M mutates s? s must be passed by reference! In fact the code we generate is just as if you'd written something like:
struct S
{
private int x;
public static void M(ref S THIS)
{
THIS.x = 123;
}
}
...
S s = new S();
S.M(ref s);
In short, a "this" in a struct already is passed as a ref parameter, so there is no problem passing it along again. Doing so is almost always a terrible idea but it is legal.