C# 是否存在枚举PCL不支持的解决方法?

C# 是否存在枚举PCL不支持的解决方法?,c#,.net,mono,portable-class-library,C#,.net,Mono,Portable Class Library,我正在使用Mono将代码转换为一个可移植类库,我遇到了一个部分,它使用System.IO.WebExceptionStatus在收到响应后切换操作。我的问题是,PCL仅支持此枚举的一部分 e、 g.ConnectionClosed不在PCL建筑的枚举内 所以有两个问题: 1) 为什么只支持枚举的一部分(我在任何地方都找不到原因)? 2) 是否有一个PCL解决方案允许我有近似的行为?1)基于此,Windows应用商店应用程序配置文件只支持有限的一组项目。在这种情况下,PCL只能支持该组项 2) 如

我正在使用Mono将代码转换为一个可移植类库,我遇到了一个部分,它使用
System.IO.WebExceptionStatus
在收到响应后切换操作。我的问题是,PCL仅支持此枚举的一部分

e、 g.
ConnectionClosed
不在PCL建筑的枚举内

所以有两个问题:
1) 为什么只支持枚举的一部分(我在任何地方都找不到原因)?
2) 是否有一个PCL解决方案允许我有近似的行为?

1)基于此,Windows应用商店应用程序配置文件只支持有限的一组项目。在这种情况下,PCL只能支持该组项

2) 如果您的应用程序确实需要处理其他项目,请不要将这段代码放在PCL中。

1)基于,Windows应用商店应用程序配置文件只支持有限的一组项目。在这种情况下,PCL只能支持该组项


2) 如果您的应用程序确实需要处理其他项目,请不要将这段代码放在PCL中。

如果您的意思是-System.Net.WebException “WebException类”

  • 系统对象
    • 系统异常
    • System.SystemException
    • System.InvalidOperationException异常
    • System.Net.WebException
.NET框架4.5,4,3.5,3.0,2.0,1.1,1.0| 客户端配置文件:4,3.5 SP1`` 可移植类库 Windows 8中支持的.NET for Windows应用商店应用程序

它已经被说了一百万次了,但pcl只是平台实现之间的共同点或交叉点的包装

我认为这一定是因为
[\uu DynamicallyInvokable]
属性

类似于Stream.Close()与Stream.Dispose()的情况,您需要切换使用或找到解决方法,对于枚举,可以强制转换为int并检查其值

// Type: System.Net.WebExceptionStatus
// Assembly: System, Version=4.0.0.0, Culture=neutral, 
namespace System.Net
{
  public enum WebExceptionStatus
  {
    Success = 0,
    ConnectFailure = 2,
    SendFailure = 4,
    RequestCanceled = 6,
    Pending = 13,
    UnknownError = 16,
    MessageLengthLimitExceeded = 17,
  }
}

或者试试已知的类型

try                        
{
//Do something that can throw WebException ? 
}
catch (WebException e)
{
if (e.Status == (WebExceptionStatus.Success) ||
    e.Status == (WebExceptionStatus.ConnectFailure) ||
    e.Status == (WebExceptionStatus.RequestCanceled) ||
    e.Status == (WebExceptionStatus.Pending) ||
    e.Status == (WebExceptionStatus.UnknownError) ||
    e.Status == (WebExceptionStatus.MessageLengthLimitExceeded))
    Debug.WriteLine("Ok");
else
    Debug.WriteLine("Its another WebException");                          
}

如果您的意思是-System.Net.WebException “WebException类”

  • 系统对象
    • 系统异常
    • System.SystemException
    • System.InvalidOperationException异常
    • System.Net.WebException
.NET框架4.5,4,3.5,3.0,2.0,1.1,1.0| 客户端配置文件:4,3.5 SP1`` 可移植类库 Windows 8中支持的.NET for Windows应用商店应用程序

它已经被说了一百万次了,但pcl只是平台实现之间的共同点或交叉点的包装

我认为这一定是因为
[\uu DynamicallyInvokable]
属性

类似于Stream.Close()与Stream.Dispose()的情况,您需要切换使用或找到解决方法,对于枚举,可以强制转换为int并检查其值

// Type: System.Net.WebExceptionStatus
// Assembly: System, Version=4.0.0.0, Culture=neutral, 
namespace System.Net
{
  public enum WebExceptionStatus
  {
    Success = 0,
    ConnectFailure = 2,
    SendFailure = 4,
    RequestCanceled = 6,
    Pending = 13,
    UnknownError = 16,
    MessageLengthLimitExceeded = 17,
  }
}

或者试试已知的类型

try                        
{
//Do something that can throw WebException ? 
}
catch (WebException e)
{
if (e.Status == (WebExceptionStatus.Success) ||
    e.Status == (WebExceptionStatus.ConnectFailure) ||
    e.Status == (WebExceptionStatus.RequestCanceled) ||
    e.Status == (WebExceptionStatus.Pending) ||
    e.Status == (WebExceptionStatus.UnknownError) ||
    e.Status == (WebExceptionStatus.MessageLengthLimitExceeded))
    Debug.WriteLine("Ok");
else
    Debug.WriteLine("Its another WebException");                          
}

1) 我明白了,但为什么会这样?我找到了其他限制的文档,但没有那个枚举。2) 因此,完全减少一半的可能结果…Microsoft从未记录为什么为某个配置文件(如CF、Silverlight、Windows Store、XBox)删除API。我能想到的唯一假设是,对于Windows应用商店应用程序,底层CLR运行时确保只有当web异常集发生时,应用程序才会收到通知。1)我知道了,但为什么会出现该子集?我找到了其他限制的文档,但没有那个枚举。2) 因此,完全减少一半的可能结果…Microsoft从未记录为什么为某个配置文件(如CF、Silverlight、Windows Store、XBox)删除API。我能想到的唯一假设是,对于Windows应用商店应用程序,底层CLR运行时确保只有在发生一组web异常时才会通知应用程序。