Suppose I want to create a set of observers based on a type. That is, when they are notified of the event, they are informed of the type of one of the arguments, and then decides whether to act or not, based on whether it can work with this type.
Are there any simple ways to do this? I figured it would be pretty easy to do with generics, but it seems to be harder than I imagined. And I would prefer not to deal with casting a reference to an object if I can avoid it.
Where am I stuck with this:
public delegate void NotifyDelegate<T>(IEnumerator<T> loadable, NotifyArgs na);
interface IObserver
{
void Notify<T>(IEnumerator<T> loadable, NotifyArgs na);
}
class Subject
{
NotifyDelegate notifier;
void Register(IObserver o)
{
notifier += o.Notify;
}
}
Of course, I could also create a Subject theme, but then I should have a separate Subject for each type. Anyone have any advice? Is there some kind of functionality that I am missing somewhere, or am I violating it too much?
. , Notify NotifyDelegate. :
public delegate void NotifyDelegate<T>(NotifyArgs na);
- :
public delegate void NotifyDelegate<T>(IEnumerator<T> loadable, NotifyArgs na);
, , . , -.