Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Strongly typed updates #3

Open
poulad opened this issue Jul 24, 2017 · 0 comments
Open

Strongly typed updates #3

poulad opened this issue Jul 24, 2017 · 0 comments

Comments

@poulad
Copy link
Member

poulad commented Jul 24, 2017

It would be nicer to handle updates of a specific type.

Cleaner code:

class MyClass {
    void RespondMessageWithWelcome(Update<MessageUpdate> msgUpdate) { }
    void ReplyToCallbackquery(Update<CallbackQueryUpdate> queryUpdate) { }
}

Possible implementation:

Update Types:

abstract class UpdateContentBase { }
class MessageUpdate : UpdateContentBase { }
class CallbackQueryUpdate : UpdateContentBase { }

New Update class:

interface IUpdate<out T> where T : UpdateContentBase, new() {
    T Content { get; }
}

class Update<T> : IUpdate<T> where T : UpdateContentBase, new() {
    public T Content { get; }
    public Update(T content) {
        Content = content;
    }
}

Not really sure if this is going to work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant