-
Notifications
You must be signed in to change notification settings - Fork 484
Closed
Description
Consider the following code sample:
[Fact]
public void TestProxy()
{
var proxy = new ProxyGenerator().CreateInterfaceProxyWithoutTarget<IInterfaceWithIn>(new RewritingInterceptor());
var val = new MutableStruct { Value = 24 };
proxy.DoNotMutate(val);
Assert.Equal(24, val.Value);
}
public struct MutableStruct
{
public int Value { get; set; }
}
public interface IInterfaceWithIn
{
void DoNotMutate(in MutableStruct value);
}
public class RewritingInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
if (invocation.Method.Name == "DoNotMutate")
{
invocation.SetArgumentValue(0, new MutableStruct {Value = 42});
}
}
}The issue happens because value is passed by ref, so technically it's possible to rewrite the value. However, like Roslyn, Castle should not allow to rewrite the value via API.
Likely, the fix should be placed somewhere here.
/cc: @stakx @blairconrad JFYI as our mock libraries contain tooling for this feature invocation.
Reactions are currently unavailable