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

Strongly typed updates #3

Open
Open
@poulad

Description

@poulad

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions