Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
En este artículo se enumeran las asignaciones que realiza C#/WinRT entre los tipos de Windows Runtime (WinRT) y los tipos de .NET en aplicaciones de escritorio destinadas a .NET 6 (o posterior). En estas aplicaciones, Visual Studio IntelliSense muestra el tipo .NET en lugar del tipo Windows Runtime. Por ejemplo, si un método Windows Runtime toma un parámetro de tipo IVector<string> a continuación, IntelliSense muestra un parámetro de tipo IList<string>. Del mismo modo, en un componente de WinRT creado con C#/WinRT, se usa el tipo .NET en las firmas de miembro. Cuando se usa C#/WinRT para generar un componente de Windows Runtime, el tipo de .NET se traduce en el tipo winRT correspondiente.
Las asignaciones de tipos personalizados de C#/WinRT se clasifican por tipos en el SDK de Windows o en WinUI 3 (WinUI forma parte del SDK de Aplicaciones para Windows). Los tipos de WinRT para las asignaciones del SDK de Windows residen en los espacios de nombres Windows.*, y los tipos de WinRT para las asignaciones de WinUI residen en los espacios de nombres Microsoft.UI.Xaml.*. Hay dos motivos para las asignaciones de tipos personalizados que C#/WinRT realiza para los tipos de WinRT:
Tipos de WinRT que se asignan a tipos de .NET con un nombre o un espacio de nombres diferente. Estas asignaciones personalizadas son para asignar tipos de WinRT a los tipos de .NET equivalentes existentes. También hay casos en los que la asignación es a un tipo diferente (por ejemplo, un tipo de valor se asigna a un tipo de clase).
Tipos de WinRT que se asignan a tipos de .NET con el mismo nombre y espacio de nombres. Estas asignaciones personalizadas suelen realizarse por motivos de rendimiento o mejora, y se implementan directamente en C#. La mayoría de los tipos que tienen el mismo nombre de espacio de nombres y nombre de tipo en WinRT y .NET son estructuras (o tipos asociados a estructuras, como enumeraciones). En WinRT, las estructuras no tienen miembros distintos de los campos y requieren tipos auxiliares, que .NET ocultan. Las versiones .NET de estas estructuras tienen propiedades y métodos que proporcionan la funcionalidad de los tipos auxiliares ocultos (por ejemplo, Windows. Interfaz de usuario. Color).
Nota:
Para obtener una lista de asignaciones entre WinRT y tipos de .NET en el contexto de las aplicaciones para UWP, consulta Asignaciones de tipos de Windows Runtime de .NET.
Asignaciones para tipos de WinRT en el SDK de Windows
Tipos con un nombre o un espacio de nombres diferente
| Tipo o espacio de nombres de WinRT | .NET tipo/espacio de nombres |
|---|---|
| DateTime (Windows.Foundation) | DateTimeOffset (System) |
| EventHandler<T> (Windows.Foundation) | EventHandler<T> (Sistema) |
| EventRegistrationToken (Windows.Foundation) | EventRegistrationToken (WinRT) |
| HResult (Windows.Foundation) | Excepción (sistema) |
| IClosable (Windows.Foundation) | IDisposable (Sistema) |
| IReference<T> (Windows.Foundation) | T< que acepta valores>NULL (sistema) |
| ** TimeSpan (Windows.Foundation) | TimeSpan (Sistema) |
| Uri (Windows.Foundation) | Uri (sistema) |
| 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) |
| Plano (Windows. Foundation.Numerics) | Plano (System.Numerics) |
| Cuaternión (Windows. Foundation.Numerics) | Cuaternión (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) | Tipo (sistema) |
Tipos con el mismo nombre y espacio de nombres
| Tipo | Namespace |
|---|---|
| IPropertyValue | Windows.Foundation |
| IReferenceArray<T> | Windows.Foundation |
| Point | Windows.Foundation |
| Rect | Windows.Foundation |
| Tamaño | Windows.Foundation |
| Color | Windows.UI |
| TypeKind | Windows. Interfaz de usuario. Xaml.Interop |
Mapeos para tipos de WinRT en WinUI
Tipos con un nombre o un espacio de nombres diferente
| Tipo o espacio de nombres de WinRT | .NET tipo/espacio de nombres |
|---|---|
| INotifyCollectionChanged (Microsoft.UI.Xaml.Data) | INotifyCollectionChanged (System.Collections.Specialized) |
| NotifyCollectionChangedEventHandler (Microsoft. Interfaz de usuario. Xaml.Data) | NotifyCollectionChangedEventHandler (System.Collections.Specialized) |
| NotifyCollectionChangedEventArgs (Microsoft. Interfaz de usuario. Xaml.Data) | NotifyCollectionChangedEventArgs (System.Collections.Specialized) |
| NotifyCollectionChangedAction (Microsoft. Interfaz de usuario. Xaml.Data) | NotifyCollectionChangedAction (System.Collections.Specialized) |
| DataErrorsChangedEventArgs (Microsoft. Interfaz de usuario. 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 (Sistema) |
Tipos con el mismo nombre y espacio de nombres
| Tipo | Namespace |
|---|---|
| CornerRadius | Microsoft.UI.Xaml |
| Duración | Microsoft.UI.Xaml |
| TipoDeDuración | Microsoft.UI.Xaml |
| GridLength | Microsoft.UI.Xaml |
| GridUnitType | Microsoft.UI.Xaml |
| Espesor | Microsoft.UI.Xaml |
| Posición del Generador | Microsoft. Interfaz de usuario. Xaml.Controls.Primitives |
| Matrix | Microsoft. Interfaz de usuario. Xaml.Media |
| KeyTime | Microsoft. Interfaz de usuario. Xaml.Media.Animation |
| ComportamientoRepetido | Microsoft. Interfaz de usuario. Xaml.Media.Animation |
| RepeatBehaviorType | Microsoft. Interfaz de usuario. Xaml.Media.Animation |
| Matrix3D | Microsoft. Interfaz de usuario. Xaml.Media.Media3D |