Does this interface already exist in the standard .NET libraries?

断了今生、忘了曾经 提交于 2020-01-04 02:04:12

问题


I found myself needing a simple generic interface, and I wrote it, but it turned out to be pretty much the world's simplest interface. I was wondering if it already exists by some other name. I just want to make sure I'm not reinventing something that is already included with the .NET framework.

interface IReceiver<T>
{
   void Receive(T obj);
}

I can't really find a good list of "standard" interfaces that came with .NET. Does the structure of this interface look familiar to anyone? Have I reinvented something that is already standard?

EDIT: I have a data object and a number of objects interested in receiving the data. Objects interested in receiving the data implement the interface, so that 'routing' lists and maps can send the data to them. The idea is full generalization in the routing, the routing will be data-driven.


回答1:


Well, it sounds like the Action<T> delegate type... I don't know of any interface equivalent off-hand, but could you just use the delegate instead?

EDIT: Okay, if you need to make the various classes actually implement it, then I'd just leave it as a new interface... especially if you can give it a slightly more meaningful name and description than IReceiver.



来源:https://stackoverflow.com/questions/13168531/does-this-interface-already-exist-in-the-standard-net-libraries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!