Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyMessenger: Parameterize sender type in ITinyMessage and descendant classes #45

Open
MhmmdAb opened this issue Sep 24, 2013 · 0 comments

Comments

@MhmmdAb
Copy link

MhmmdAb commented Sep 24, 2013

I'm working on a project where I'm finding myself repeatedly downcasting the Sender property in ITinyMessage and co to more concrete types to access their properties. So I thought it would be nice to have variants of ITinyMessage, TinyMessageBase, and GenericTinyMessage that take the sender type as a generic type parameter.

Here's an example of what it could look like using sender of type Foo, receiver of type Bar, and message of type FooHitTheBarMessage:

public class Foo
{
    public float Speed { get; private set; }

    //
    // Omitted details
    //
}

public class FooHitTheBarMessage : TinyMessageBase<Foo>
{
    public FooHitTheBarMessage(Foo sender)
        : base(sender)
    {   
    }
}

public class Bar
{
    public void Init()
    {
        MessageBus.Subscribe<FooHitTheBarMessage>(msg =>
        {
            TallyDamageBasedOnHitSpeed(msg.Sender.Speed);
        });
    }

    //
    // Omitted details
    //
}
MhmmdAb added a commit to MhmmdAb/TinyIoC that referenced this issue Sep 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant