在便携式类库实现自定义异常 [英] Implementing custom exceptions in a Portable Class Library

查看:128
本文介绍了在便携式类库实现自定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计定制例外。NET,MSDN提供这些准则。特别是,准则规定,自定义异常:

When designing custom exceptions for .NET, MSDN provides these guidelines. In particular, the guidelines state that a custom exception:

  • 应该是可序列化,即实施 ISerializable的,并用 [Serializable接口] 属性,
  • 应该实现(德)序列化的构造,即保护CustomException(SerializationInfo中的信息,的StreamingContext上下文)
  • should be serializable, i.e. implement ISerializable and be decorated with the [Serializable] attribute, and
  • should implement the (de)serialization constructor, i.e. protected CustomException(SerializationInfo info, StreamingContext context).

然而,在便携式类库既不 SerializableAttribute ISerializable的的SerializationInfo 支持。

However, in a Portable Class Library neither of SerializableAttribute, ISerializable and SerializationInfo are supported.

我应该如何充分地在便携式类库,能同时针对.NET Framework和一个或多个平台设计自定义异常?

How should I sufficiently design a custom exception in a Portable Class Library that simultaneously targets .NET Framework and one or more platforms?

推荐答案

基本上忽略了指导 - 这是完整的.NET,而并不适用于便携式类库项目。事实上,如果我们看一下(说) Silverlight的 (其中包括WP7),我们看到:

Basically, ignore that guidance - that is for full .NET, and does not apply to portable class library projects. Indeed, if we look at (say) Silverlight (which includes WP7) we see:

[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
public class Exception

坦率地说,这一要求的主要消费者是的远程的...这是不是在巨大的需求了。

Frankly, the main consumer of that requirement was remoting... and that is not in huge demand now.

这篇关于在便携式类库实现自定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆