访问用户类别主连接关闭时的属性
我正在构建一个 Messenger 类库。登录后,您可以通过 msgrinstance.Users 访问用户对象列表的集合。这些用户具有 LoginName、FriendlyName、DisplayPicture 等属性。
如果您在注销后尝试访问 .Users,则会引发 NotLoggedInException。对于登录时创建的任何用户类,如果您尝试访问它们的任何属性,您将再次收到 NotLoggedInException。
这是一个好的做事方式吗?也许对于用户属性,我应该抛出 InvalidOperationException,因为用户类不再与主 Messenger 类链接?
I am building a Messenger class library. When logged in, you can access a collection of user objects list via msgrinstance.Users. These users have properties such as LoginName, FriendlyName, DisplayPicture.
If you try to access .Users after logging out, a NotLoggedInException is thrown. And for any user classes that were created while being logged in, if you try to access any of their properties you will again get a NotLoggedInException.
Is this a good way of doing things? Perhaps for the user properties I should be throwing an InvalidOperationException, as the user class is no longer linked with the main Messenger class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会在任何 ptoperty 中添加控件,而是在从对象请求该信息的函数中添加一个控件,或者只是在应用程序注销后清除用户集合。
或者,如果您只是出于某种原因想要在注销后列出用户列表,我个人建议不要抛出异常,而是返回一些“无效”值。
编辑:
如果客户端仅持有 User 对象的引用,如果不是 GC 收集,它就不会产生问题,但它肯定会在决定用它做某事的那一刻产生问题,所以调用一个函数,所以添加您的 API 访问中的错误处理。
希望这有帮助。
问候。
Instead of adding control in any ptoperty I would add a control in a function that requests that information from object, or just clear user collection after app logged off.
Or, if you just want for some reason have users list even after logoff, I would personally suggest to not throw an exception, but return some "invalid" value.
EDIT:
If a client holds just a refence of a User object it can not create problem, if not for GC collection, but it definitely can create a problem at a moment it decides to DO something with it, so call a function, so add error handling there, on your API access.
Hope this helps.
Regards.