当您创建 Windows 运行时组件时,您的组件可以由不受管理的语言使用,例如 Javascript 或 C++。显然,这些语言不知道如何生成正确的 System.DateTime,它是一种特定的 .NET 类型。
因此,此类组件必须仅使用本机 WinRT 类型,否则必须遵守 WinRT 中存在的限制。您从一开始就会遇到这样一个限制,即 WinRT 不支持实现继承。这需要您声明您的班级seal。
本机 WinRT 类型与 .NET 类型非常不同。可以存储日期的真正运行时类型是 Windows.Foundation.DateTime。字符串实际上是一个 HSTRING 句柄。List 实际上是一个 IVector。等等。
Needless to say, if you would actually have to use those native types then your program wouldn't resemble a .NET program anymore. And you don't, the .NET 4.5 version of the CLR has a language projection built in. Code that automatically translates WinRT types to their equivalent .NET types. That translation has a few rough edges, some types cannot easily be substituted. But the vast majority of them map without trouble.
System.DateTime is one such rough edge. The language projection of Windows.Foundation.DateTime is System.DateTimeOffset. So simply solve your problem by declaring your method like this:
public DateTimeOffset Calculate(DateTimeOffset dateTime) {
// etc..
}
The only other point worth noting is that this is only required for members that other code might use. Public members.