简体   繁体   English

事件参数中IEnumerable的最佳实践

[英]Best Practice for IEnumerable in event arguments

I have a DLL including a class for managing audio and midi ports and connections. 我有一个DLL,包括一个用于管理音频和midi端口和连接的类。 Whenever ports are registered or deregistered or connections are formed or released, this class fires an event, like ConnectionChanged with custom event arguments including properties Enum ChangeType and IEnumerable<Connection> ChangedConnections 无论何时注册或取消注册端口或形成或释放连接,此类都会触发一个事件,例如ConnectionChanged ,其中包含自定义事件参数,包括属性Enum ChangeTypeIEnumerable<Connection> ChangedConnections

Now my question is: Should I really just send the changed connections or change the property of the event args to Connections and send an IEnumerable containing all active connections? 现在我的问题是:我是否真的只是发送更改的连接或将事件args的属性更改为Connections并发送包含所有活动连接的IEnumerable?

In my opinion, the event is called "ConnectionChanged", you should include the connections that apply to that event in your event arguments. 在我看来,该事件被称为“ConnectionChanged”,您应该在事件参数中包含适用于该事件的连接。 Make all active connections accessible using a member on your class. 使用班级中的成员访问所有活动连接。

When firing the event. 发射事件时。 You send the actual object that raised the event in the member Sender. 您在成员发件人中发送引发事件的实际对象。 So if someone is actually interested in all active connections, it can be obtained through the Sender object. 因此,如果某人实际上对所有活动连接感兴趣,则可以通过Sender对象获取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM