c# - 找不到类型或命名空间名称 'IConvertible'

标签 c# portable-class-library iconvertible

我正在尝试为自定义转换实现 IConvertible。我正在使用 .NET portable,但它似乎在那里不可用。但是 MSDN documentation说:

Portable Class Library
Supported in: Portable Class Library

我有点担心这也出现了:

This API is not CLS-compliant.

这就是它可能得不到解决的原因吗? 根据文档,它应该是 System 命名空间的一部分。 我正在尝试在结构中实现接口(interface)。

关于 :

public struct ABC: Blah<Demo>, IConvertible 
{}

我觉得我错过了一些非常小的东西。
更多信息:我的目标是 .NET Framework 4.5 和 Windows 8。

最佳答案

“Supported in: Portable Class Library”只是确定它是否在您的方案中受支持的开始。您还必须查看有关支持的更多信息,以了解您的 PCL 目标是否受支持。您已经说过您的目标是 .NET Framework 4.5 和 Windows 8。让我们比较一下 IConvertibleIComparable 的支持信息:

IConvertible :

.NET Framework
Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client Profile
Supported in: 4, 3.5 SP1
Portable Class Library
Supported in: Portable Class Library
.NET for Windows Phone apps
Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

IComparable :

.NET Framework
Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client Profile
Supported in: 4, 3.5 SP1
Portable Class Library
Supported in: Portable Class Library
.NET for Windows Store apps
Supported in: Windows 8
.NET for Windows Phone apps
Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

因此,在我们确定“它在 PCL 中受支持”之后,您需要查看其他部分并将其与您的目标集进行比较。如果您的任何目标未列为受支持,则您将无法在当前 PCL 中使用该类型(不删除不受支持的目标)

关于c# - 找不到类型或命名空间名称 'IConvertible',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25562733/

相关文章:

c# - 在c#中实现两个具有相同功能的接口(interface)

c# - 隐式运算符和泛型类

c# - IsInstanceOfType 或新的 .Net Type/TypeInfo API 中的等效项在哪里?

c# - IConvertible 接口(interface)如何与 DataRow 一起工作?

c# - 如何检查两种类型是否可以进行比较、求和等?

c# - 从另一个列表中删除列表的内容

c# - 如果 ASP.NET 5 应用程序在 Ubuntu 上运行,它可以与 MS SQL Server 通信吗?

c# - 在 Windows 10 通用 Windows 库中引用 BindingFlags 类型时无法加载程序集

xaml - 在 Xamarin.Forms PCL XAML 页面中禁用自动完成

c# - 为什么 .Net Framework 基类型不包含 IConvertible 方法的实现?