Open samasama opened 7 years ago
Currently, Prig doesn't support the way to use, but a workaround exists:
A.Id
.In the Indirection Stub, compare an instance of B
and @this
then return dummy value if it is true; otherwise @this.Id
with IndirectionsContext.ExecuteOriginal
. Here is the example:
[Test]
public void B_Id_should_be_callable_indirectly_but_does_not_replace_A_Id()
{
using (new IndirectionsContext())
{
// Arrange
var a = new A();
var b = new B();
PA.IdGet().Body = @this => ReferenceEquals(@this, b) ? 1 : IndirectionsContext.ExecuteOriginal(() => @this.Id);
// Act
var aid = a.Id;
var bid = b.Id;
// Assert
Assert.AreEqual(42, aid);
Assert.AreEqual(1, bid);
}
}
Full sln is here: Issues99.zip
I have a class B that inherits class A, with method A.Id I created the indirection settings for B non inherited methods and for B.Id
I cannot replace the body for B.Id as in:
bProxy = new PProxyB(); bProxy.Id().Body = @this => 1;
Error: PProxyB does not contain a definition for "Id"
Is there a way to cast bProxy to PProxyA?