Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Questo articolo elenca i mapping che C#/WinRT crea tra i tipi Windows Runtime (WinRT) e i tipi di .NET nelle app desktop destinate a .NET 6 (o versione successiva). In queste app, Visual Studio IntelliSense mostra il tipo di .NET anziché il tipo di Windows Runtime. Ad esempio, se un metodo Windows Runtime accetta un parametro di tipo IVector<string>, Quindi IntelliSense mostra un parametro di tipo IList<string>. Analogamente, in un componente WinRT creato con C#/WinRT, si usa il tipo di .NET nelle firme dei membri. Quando si usa C#/WinRT per generare un componente Windows Runtime, il tipo di .NET viene convertito nel tipo WinRT corrispondente.
I mapping dei tipi personalizzati C#/WinRT sono classificati in base ai tipi nell'SDK Windows o in WinUI 3 (WinUI fa parte del SDK per app di Windows). I tipi WinRT per i mapping Windows SDK si trovano negli spazi dei nomi Windows.*, e i tipi WinRT per i mapping WinUI si trovano negli spazi dei nomi Microsoft.UI.Xaml.*. Esistono due motivi per l'associazione personalizzata dei tipi effettuata da C#/WinRT per i tipi di WinRT:
Tipi WinRT che eseguono il mapping ai tipi di .NET con un nome e/o uno spazio dei nomi diversi. Queste mappature personalizzate sono per mappare i tipi WinRT ai tipi equivalenti esistenti in .NET. Esistono anche casi in cui il mapping avviene verso un tipo diverso, ad esempio un tipo di valore è mappato a un tipo di classe.
Tipi WinRT che si mappano ai tipi .NET con lo stesso nome e spazio dei nomi. Questi mapping personalizzati sono in genere per motivi di prestazioni o miglioramento e vengono implementati direttamente in C#. La maggior parte dei tipi con lo stesso nome dello spazio dei nomi e lo stesso nome di tipo in WinRT e .NET sono strutture (o tipi associati a strutture, ad esempio enumerazioni). In WinRT le strutture non hanno membri oltre ai campi e richiedono tipi helper, che .NET nasconde. Le versioni .NET di queste strutture hanno proprietà e metodi che forniscono la funzionalità dei tipi helper nascosti, ad esempio Windows. UI. Colore).
Nota
Per un elenco dei mapping tra tipi WinRT e .NET nel contesto delle app UWP, vedi i mapping .NET dei tipi di Windows Runtime.
Mappe per i tipi WinRT nel SDK di Windows
Tipi con un nome e/o un namespace diverso
| Tipo/nome WinRT | .NET tipo/spazio dei nomi |
|---|---|
| DateTime (Windows.Foundation) | DateTimeOffset (System) |
| EventHandler<T> (Windows.Foundation) | EventHandler<T> (sistema) |
| EventRegistrationToken (Windows.Foundation) | EventRegistrationToken (WinRT) |
| HResult (Windows.Foundation) | Eccezione (sistema) |
| IClosable (Windows.Foundation) | IDisposable (Sistema) |
| IReference<T> (Windows.Foundation) | T< Nullable> (Sistema) |
| TimeSpan (Windows.Foundation) | TimeSpan (sistema) |
| URI (Windows. Fondazione) | 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) |
| Piano (Windows. Foundation.Numerics) | Piano (System.Numerics) |
| Quaternione (Windows. Foundation.Numerics) | Quaternione (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) |
Tipi con lo stesso nome e lo stesso spazio dei nomi
| Tipo | Namespace |
|---|---|
| IPropertyValue | Windows.Foundation |
| IReferenceArray<T> | Windows.Foundation |
| Punto | Windows.Foundation |
| Rett | Windows.Foundation |
| Grandezza | Windows.Foundation |
| Colore | Windows.UI |
| TypeKind | Windows.UI.Xaml.Interop |
Mappature per i tipi dei WinRT in WinUI
Tipi con un nome e/o un namespace diverso
| Tipo/nome WinRT | .NET tipo/spazio dei nomi |
|---|---|
| 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 (System) |
Tipi con lo stesso nome e lo stesso spazio dei nomi
| Tipo | Namespace |
|---|---|
| CornerRadius | Microsoft. UI. Xaml |
| Durata | Microsoft. UI. Xaml |
| Tipo di Durata | Microsoft. UI. Xaml |
| GridLength | Microsoft. UI. Xaml |
| GridUnitType | Microsoft. UI. Xaml |
| Spessore | Microsoft. UI. Xaml |
| GeneratorPosition | Microsoft.UI.Xaml.Controls.Primitives |
| Matrice | Microsoft.UI.Xaml.Media |
| KeyTime | Microsoft. UI. Xaml.Media.Animation |
| RepeatBehavior | Microsoft. UI. Xaml.Media.Animation |
| TipoDiComportamentoRipetuto | Microsoft. UI. Xaml.Media.Animation |
| Matrix3D | Microsoft.UI.Xaml.Media.Media3D |