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

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

问题描述

在设计.NET的自定义异常时,MSDN提供了这些准则 。特别是,该指南规定,自定义异常:

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


  • 应该是可序列化的,即实现 ISerializable 并使用 [Serializable] 属性进行装饰,

  • 应实现(de)序列化构造函数,即 protected CustomException(SerializationInfo info,StreamingContext context)

  • 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

我应该如何在可移植类库中充分设计一个自定义异常,同时针对.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

坦白说,这个要求的主要消费者是 remoting ...现在不是很大的需求。

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

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

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