tags:

views:

117

answers:

1

Shouldn't this test pass:

[TestMethod]
public void derived_message_subscription()
{
    bool handled = false;
    Messenger.Default.Register<GenericMessage<baseClass>>(this, true, (msg) => handled = true);
    Messenger.Default.Send(new GenericMessage<testClass>(new testClass()));
    Assert.IsTrue(handled);
}

public abstract class baseClass { }
public class testClass : baseClass { }

I have to receive all messages for classes that inherits from one base class. MVVMLight has bool property receiveDerivedMessagesToo in Register method, but it seems to me that it isn't working.

Note that when I don't use GenericMessage < T >, test pass. Is it bug in galasoft mvvm light, or feature?

+1  A: 

receiveDerivedMessagesToo means that you will receive messages that derive from the message class that you registered. This would work:

public class SpecificMessage : GenericMessage { }

As far as I know, you can't register to one generic type and receive all the types that are derived from this generic, because GenericMessage<testClass> does not derive from GenericMessage<baseClass>.

AlexB
Yes, that was my conclusion also.
Hrvoje