为什么 InvalidEnumArgumentException 在 Silverlight 4 中已过时?
我惊讶地发现 < code>InvalidEnumArgumentException 已在 Silverlight 4 中过时。
有谁知道这是为什么?我发现这是一个非常有用的异常,特别是在手动将二进制数据反序列化为枚举值时。
[ObsoleteAttribute(
"InvalidEnumArgumentException is obsolete. Use ArgumentException instead.")]
public class InvalidEnumArgumentException : Exception
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,它被标记为已过时,但完全存在(这里是 指向该类的 Silverlight 版本的正确链接)
我认为这个特定的“为什么”问题对于这里的每个人来说都很难回答,因为他们不在微软工作并且参与审查此类变更的过程。微软可能有某种文档解释了在当前版本中将其标记为过时的高级原因。现在就是这样,我担心你可能不得不忍受它。
出于兴趣,我用 bing 搜索了一下,这里的这个帖子是我能找到的关于该主题的最佳帖子。即使在 Silverlight.net 上查找也不会产生任何结果。因此,您要么需要一份金牌合作伙伴合同(或其他任何名称),然后直接联系 Microsoft 的人员来解决此问题。
然而,对于这个同样的异常似乎存在一些争议,无论是否使用它是好的做法,我想引用对此的评论 链接,谈论不一致:
因此,这可能也是导致将其从 Silverlight 中删除的整个情况的原因。或不。也许只是因为他们认为这是不必要的开销,可以这么说,因为你可能无论如何都会捕获 ArgumentException,并且大多数实现通过进一步分解它不会获得任何好处。这只是一个猜测,但我担心你不会得到比这更好的结果(除了其他随机猜测)。
如果您愿意,您当然可以添加自己的 InvalidEnumArgumentException 实现,而且我猜您已经这样做了。
You are right, it is marked obsolete but totally there (here is the correct link pointing to the Silverlight Version of the class)
I think this particular "Why" question is hard to answer for everyone here, who is not working at microsoft and involved in the process of reviewing such changes. There is probably some kind of document at Microsoft explaining the high-level reasons for marking it obsolete in the current version. It is as it is right now and i fear you might have to live with it.
Out of intereset i googled a bit with bing and this SO thread here was the best hit on the topic i could find. Even looking for it on Silverlight.net die not yield any results. So either you need a gold partner contract (or whatever its called) and contact the guys at Microsoft directly on the issue.
However there seems a bit controvery going on over this very same Exception, wether its good practice to use it or not, i would like to quote a comment on this link, talking about inconsistensies:
So that might have also played into the whole circumstance that lead to removing it from Silverlight. Or not. Maybe its just because they thought its unneeded overhead, so to say, because you are probably catching ArgumentExceptions anyway and most implementatoins gain nothing by further breaking it down. Its just a guess, but i am afraid you wont get any better than this (besides other random guesses).
You could of course add your own InvalidEnumArgumentException implementation if you wanted to, and i would guess that you have already done so.