Partager via


.NET mappages de types WinRT en C#/WinRT

Cet article répertorie les mappages que C#/WinRT effectue entre les types Windows Runtime (WinRT) et les types .NET dans les applications de bureau qui ciblent .NET 6 (ou version ultérieure). Dans ces applications, Visual Studio IntelliSense affiche le type .NET au lieu du type Windows Runtime. Par exemple, si une méthode Windows Runtime accepte un paramètre de type IVector<string>, IntelliSense affiche un paramètre de type IList<string>. De même, dans un composant WinRT créé à l’aide de C#/WinRT, vous utilisez le type de .NET dans les signatures de membre. Lorsque vous utilisez C#/WinRT pour générer un composant Windows Runtime, le type .NET est traduit en type WinRT correspondant.

Les mappages de types personnalisés C#/WinRT sont classés par types dans le Kit de développement logiciel (SDK) Windows ou dans WinUI 3 (WinUI fait partie de la SDK d'application Windows). Les types WinRT pour les mappages du SDK Windows se trouvent sous les espaces de noms Windows.*, et les types WinRT pour les mappages WinUI se trouvent sous les espaces de noms Microsoft.UI.Xaml.*. Il existe deux raisons pour les mappages de types personnalisés que C#/WinRT effectue pour les types WinRT :

  • Types WinRT mappés à des types .NET avec un autre nom et/ou espace de noms. Ces mappages personnalisés permettent de mapper des types WinRT à des types .NET équivalents existants. Il existe également des cas où le mappage est d’un type différent (par exemple, un type valeur est mappé à un type de classe).

  • Types WinRT correspondant aux types .NET portant le même nom et le même espace de noms. Ces mappages personnalisés sont généralement destinés à des raisons de performances ou d’amélioration, et sont implémentés directement en C#. La plupart des types qui ont le même nom d’espace de noms et le même nom de type dans WinRT et .NET sont des structures (ou des types associés à des structures, telles que des énumérations). Dans WinRT, les structures n’ont aucun membre autre que les champs et nécessitent des types d'assistance supplémentaires, que .NET cache. Les versions .NET de ces structures ont des propriétés et des méthodes qui fournissent les fonctionnalités des types d’assistance masqués (par exemple, Windows. UI. Couleur).

Note

Pour obtenir la liste des mappages entre les types WinRT et .NET dans le contexte des applications UWP, consultez Mappages .NET des types Windows Runtime.

Mappages pour les types WinRT dans le Kit de développement logiciel (SDK) Windows

Types avec un nom et/ou un espace de noms différents

Type/espace de noms WinRT .NET type/espace de noms
DateTime (Windows.Foundation) DateTimeOffset (System)
EventHandler<T> (Windows.Foundation) EventHandler<T> (Système)
EventRegistrationToken (Windows.Foundation) EventRegistrationToken (WinRT)
HResult (Windows.Foundation) Exception (système)
IClosable (Windows.Foundation) IDisposable (Système)
IReference<T> (Windows. Fondation) Nullable<T> (Système)
TimeSpan (Windows.Foundation) TimeSpan (Système)
Uri (Windows.Foundation) Uri (système)
IIterable<T> (Windows. Foundation.Collections) IEnumerable<T> (System.Collections.Generic)
IIterator<T> (Windows. Foundation.Collections) IEnumerator<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)
IVector<T> (Windows. Foundation.Collections) IList<T> (System.Collections.Generic)
IVectorView<T> (Windows. Foundation.Collections) IReadOnlyList<T> (System.Collections.Generic)
AttributeTargets (Windows. Foundation.Metadata) AttributeTargets (System)
AttributeUsageAttribute (Windows. Foundation.Metadata) AttributeUsageAttribute (System)
Matrix3x2 (Windows. Foundation.Numerics) Matrix3x2 (System.Numerics)
Matrix4x4 (Windows. Foundation.Numerics) Matrix4x4 (System.Numerics)
Plan (Windows. Foundation.Numerics) Plan (System.Numerics)
Quaternion (Windows. Foundation.Numerics) Quaternion (System.Numerics)
Vector2 (Windows. Foundation.Numerics) Vector2 (System.Numerics)
Vector3 (Windows. Foundation.Numerics) Vector3 (System.Numerics)
Vector4 (Windows. Foundation.Numerics) Vector4 (System.Numerics)
IBindableIterable (Windows. UI. Xaml.Interop) IEnumerable (System.Collections)
IBindableVector (Windows. UI. Xaml.Interop) IList (System.Collections)
TypeName (Windows. UI. Xaml.Interop) Type (système)

Types ayant le même nom et l'espace de noms

Type Namespace
IPropertyValue Windows.Foundation
IReferenceArray<T> Windows.Foundation
Point Windows.Foundation
Rect Windows.Foundation
Taille Windows.Foundation
Color Windows.UI
TypeKind Windows.UI.Xaml.Interop

Mappages pour les types WinRT dans WinUI

Types avec un nom et/ou un espace de noms différents

Type/espace de noms WinRT .NET type/espace de noms
INotifyCollectionChanged (Microsoft. UI. Xaml.Data) INotifyCollectionChanged (System.Collections.Specialized)
NotifyCollectionChangedEventHandler (Microsoft. UI. Xaml.Data) NotifyCollectionChangedEventHandler (System.Collections.Specialized)
NotifyCollectionChangedEventArgs (Microsoft. UI. Xaml.Data) NotifyCollectionChangedEventArgs (System.Collections.Specialized)
NotifyCollectionChangedAction (Microsoft. UI. Xaml.Data) NotifyCollectionChangedAction (System.Collections.Specialized)
DataErrorsChangedEventArgs (Microsoft. UI. Xaml.Data) DataErrorsChangedEventArgs (System.ComponentModel)
INotifyDataErrorInfo (Microsoft.UI.Xaml.Data) INotifyDataErrorInfo (System.ComponentModel)
INotifyPropertyChanged (Microsoft.UI.Xaml.Data) INotifyPropertyChanged (System.ComponentModel)
PropertyChangedEventHandler (Microsoft. UI. Xaml.Data) PropertyChangedEventHandler (System.ComponentModel)
PropertyChangedEventArgs (Microsoft. UI. Xaml.Data) PropertyChangedEventArgs (System.ComponentModel)
ICommand (Microsoft. UI. Xaml.Input) ICommand (System.Windows.Input)
IXamlServiceProvider (Microsoft. UI. Xaml) IServiceProvider (Système)

Types ayant le même nom et l'espace de noms

Type Namespace
Cornerradius Microsoft. UI. Xaml
Durée Microsoft. UI. Xaml
DurationType Microsoft. UI. Xaml
GridLength (longueur de grille) Microsoft. UI. Xaml
GridUnitType Microsoft. UI. Xaml
Épaisseur Microsoft. UI. Xaml
PositionDuGénérateur Microsoft.UI.Xaml.Controls.Primitives
Matrix Microsoft.UI.Xaml.Media
Keytime Microsoft. UI. Xaml.Media.Animation
RepeatBehavior Microsoft. UI. Xaml.Media.Animation
RepeatBehaviorType Microsoft. UI. Xaml.Media.Animation
Matrix3d Microsoft.UI.Xaml.Media.Media3D