开发者

Access to a user class' properties when main connection has been closed

I am building a Messenger class library. W开发者_如何学Chen 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜