UWP 应用中的 Windows 运行时类型的 .NET 映射

本文列出了 .NET 在以托管代码编写的通用 Windows 平台 (UWP) 应用的 Windows 运行时 (WinRT) 类型和 .NET 类型之间进行的映射。 在这些应用中,Visual Studio IntelliSense 显示 .NET 类型而不是 WinRT 类型。 例如,如果 WinRT 方法采用 IVector<字符串>类型的参数,则 IntelliSense 将显示 IList<字符串>类型的参数。 同样,在使用托管代码编写的 Windows 运行时组件中,你将使用成员签名中的 .NET 类型。 当 Windows 运行时元数据导出工具 (Winmdexp.exe) 生成 Windows 运行时组件时,.NET 类型将转换为相应的 WinRT 类型。

在 WinRT 和 .NET 中,大多数具有相同的命名空间名称和类型名称的类型都是结构(或者与结构关联的类型,例如枚举)。 在 WinRT 中,结构没有字段以外的成员,并且需要帮助器类型(.NET 会隐藏这些类型)。 这些 .NET 版本的结构具有可提供隐藏帮助程序类型的功能的属性和方法。

注意

有关面向 .NET 并使用 C#/WinRT 的桌面应用上下文中 WinRT 和 .NET 类型之间的映射列表,请参阅 C#/WinRT 中 WinRT 类型的 .NET 映射

映射到具有相同名称和命名空间的 .NET 类型的 WinRT 类型

在 .NET 程序集 System.ObjectModel.dll 中

命名空间 类型
Windows.UI.Xaml.Input ICommand

在 .NET 程序集 System.Runtime.WindowsRuntime.dll 中

命名空间 类型
Windows.Foundation
Windows.Foundation Rect
Windows.Foundation 大小
Windows.UI Color

在 .NET 程序集 System.Runtime.WindowsRuntime.UI.Xaml.dll 中

命名空间 类型
Windows.UI.Xaml CornerRadius
Windows.UI.Xaml 持续时间
Windows.UI.Xaml DurationType
Windows.UI.Xaml GridLength
Windows.UI.Xaml GridUnitType
Windows.UI.Xaml Thickness
Windows.UI.Xaml.Controls.Primitives GeneratorPosition
Windows.UI.Xaml.Media 矩阵
Windows.UI.Xaml.Media.Animation KeyTime
Windows.UI.Xaml.Media.Animation RepeatBehavior
Windows.UI.Xaml.Media.Animation RepeatBehaviorType
Windows.UI.Xaml.Media.Media3D Matrix3D

映射到具有不同名称和/或命名空间的 .NET 类型的 WinRT 类型

在 .NET 程序集 System.ObjectModel.dll 中

WinRT 类型/命名空间 .NET 类型/命名空间
INotifyCollectionChanged (Windows.UI.Xaml.Interop) INotifyCollectionChanged (System.Collections.Specialized)
NotifyCollectionChangedEventHandler (Windows.UI.Xaml.Interop) NotifyCollectionChangedEventHandler (System.Collections.Specialized)
NotifyCollectionChangedEventArgs (Windows.UI.Xaml.Interop) NotifyCollectionChangedEventArgs (System.Collections.Specialized)
NotifyCollectionChangedAction (Windows.UI.Xaml.Interop) NotifyCollectionChangedAction (System.Collections.Specialized)
INotifyPropertyChanged (Windows.UI.Xaml.Data) INotifyPropertyChanged (System.ComponentModel)
PropertyChangedEventHandler (Windows.UI.Xaml.Data) PropertyChangedEventHandler (System.ComponentModel)
PropertyChangedEventArgs (Windows.UI.Xaml.Data) PropertyChangedEventArgs (System.ComponentModel)

在 .NET 程序集 System.Runtime.dll 中

WinRT 类型/命名空间 .NET 类型/命名空间
AttributeUsageAttribute (Windows.Foundation.Metadata) AttributeUsageAttribute (System)
AttributeTargets (Windows.Foundation.Metadata) AttributeTargets (System)
DateTime (Windows.Foundation) DateTimeOffset (System)
EventHandler<T> (Windows.Foundation) EventHandler<T> (System)
HResult (Windows.Foundation) Exception (System)
IReference<T> (Windows.Foundation) Nullable<T> (System)
TimeSpan (Windows.Foundation) TimeSpan (System)
Uri (Windows.Foundation) Uri (System)
IClosable (Windows.Foundation) IDisposable (System)
IIterable<T> (Windows.Foundation.Collections) IEnumerable<T> (System.Collections.Generic)
IVector<T> (Windows.Foundation.Collections) IList<T> (System.Collections.Generic)
IVectorView<T> (Windows.Foundation.Collections) IReadOnlyList<T> (System.Collections.Generic)
IMap<K,V> (Windows.Foundation.Collections) IDictionary<TKey,TValue> (System.Collections.Generic)
IMapView<K,V> (Windows.Foundation.Collections) IReadOnlyDictionary<TKey,TValue> (System.Collections.Generic)
IKeyValuePair<K,V> (Windows.Foundation.Collections) KeyValuePair<TKey,TValue> (System.Collections.Generic)
IBindableIterable (Windows.UI.Xaml.Interop) IEnumerable (System.Collections)
IBindableVector (Windows.UI.Xaml.Interop) IList (System.Collections)
TypeName (Windows.UI.Xaml.Interop) Type (System)

在 .NET 程序集 System.Runtime.InteropServices.WindowsRuntime.dll 中

WinRT 类型/命名空间 .NET 类型/命名空间
EventRegistrationToken (Windows.Foundation) EventRegistrationToken (System.Runtime.InteropServices.WindowsRuntime)