Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Este artigo lista os mapeamentos que o C#/WinRT faz entre os tipos de Windows Runtime (WinRT) e os tipos de .NET em os aplicativos da área de trabalho direcionados ao .NET 6 (ou posterior). Nesses aplicativos, Visual Studio IntelliSense mostra o tipo .NET em vez do tipo Windows Runtime. Por exemplo, se um método Windows Runtime usa um parâmetro do tipo IVector<string>, Em seguida, o IntelliSense mostra um parâmetro do tipo IList<string>. Da mesma forma, em um componente WinRT criado usando C#/WinRT, você usa o tipo .NET em assinaturas de membro. Quando você usa C#/WinRT para gerar um componente Windows Runtime, o tipo .NET é convertido no tipo WinRT correspondente.
Os mapeamentos de tipo personalizado C#/WinRT são categorizados por tipos no SDK do Windows ou em WinUI 3 (o WinUI faz parte do SDK do Aplicativo Windows). Os tipos WinRT para mapeamentos do SDK do Windows estão nos namespaces Windows.*, e os tipos WinRT para mapeamentos do WinUI estão nos namespaces Microsoft.UI.Xaml.*. Há dois motivos para mapeamentos de tipo personalizados que o C#/WinRT faz para tipos WinRT:
Tipos de WinRT que são mapeados para tipos de .NET com um nome e/ou namespace diferentes. Esses mapeamentos personalizados são para mapear tipos WinRT para tipos equivalentes .NET existentes. Também há casos em que o mapeamento é de um tipo diferente (por exemplo, um tipo de valor é mapeado para um tipo de classe).
Tipos winRT que mapeiam para tipos de .NET com o mesmo nome e namespace. Esses mapeamentos personalizados geralmente são por motivos de desempenho ou aprimoramento e são implementados diretamente em C#. A maioria dos tipos que têm o mesmo nome de namespace e nome de tipo no WinRT e .NET são estruturas (ou tipos associados a estruturas, como enumerações). No WinRT, as estruturas não têm membros que não sejam campos e exigem tipos auxiliares, que .NET oculta. As versões .NET dessas estruturas têm propriedades e métodos que fornecem a funcionalidade dos tipos auxiliares ocultos (por exemplo, Windows. UI. Cor).
Observação
Para obter uma lista de mapeamentos entre tipos do WinRT e .NET no contexto de aplicativos UWP, consulte Mapeamentos de tipos do Windows Runtime em .NET.
Mapeamentos para tipos WinRT no SDK do Windows
Tipos com um nome e/ou namespace diferentes
| Tipo/espaço de nomes do WinRT | .NET tipo/namespace |
|---|---|
| DateTime (Windows.Foundation) | DateTimeOffset (Sistema) |
| EventHandler<T> (Windows.Foundation) | EventHandler<T> (Sistema) |
| EventRegistrationToken (Windows.Foundation) | EventRegistrationToken (WinRT) |
| HResult (Windows.Foundation) | Exceção (Sistema) |
| IClosable (Windows.Foundation) | IDisposable (System) |
| IReference<T> (Windows.Foundation) | T< anulável>(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) | TKey IReadOnlyDictionary<, 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 (Sistema) |
| AttributeUsageAttribute (Windows. Foundation.Metadata) | AttributeUsageAttribute (System) – Classe dentro do namespace System, utilizada para definir como um atributo pode ser aplicado em um código-fonte. |
| Matrix3x2 (Windows. Foundation.Numerics) | Matrix3x2 (System.Numerics) |
| Matrix4x4 (Windows. Foundation.Numerics) | Matrix4x4 (System.Numerics) |
| Plano (Windows. Foundation.Numerics) | Plano (System.Numerics) |
| Quatérnio (Windows. Foundation.Numerics) | Quatérnio (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 com o mesmo nome e namespace
| Tipo | Namespace |
|---|---|
| IPropertyValue | Windows.Foundation |
| IReferenceArray<T> | Windows.Foundation |
| Point | Windows.Foundation |
| Rect | Windows.Foundation |
| Tamanho | Windows.Foundation |
| Cor | Windows.UI |
| TypeKind | Windows.UI.Xaml.Interop |
Mapeamentos para tipos WinRT no WinUI
Tipos com um nome e/ou namespace diferentes
| Tipo/espaço de nomes do WinRT | .NET tipo/namespace |
|---|---|
| INotifyCollectionChanged (Microsoft. UI. Xaml.Data) | INotifyCollectionChanged (System.Collections.Specialized) |
| NotifyCollectionChangedEventHandler (Microsoft. UI. Xaml.Data) | NotifyCollectionChangedEventHandler (System.Collections.Specialized) |
| NotifyCollectionChangedEventArgs (Microsoft. UI. Xaml.Data) | Argumentos do Evento de Notificação de Alteração de Coleção (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 (Sistema) |
Tipos com o mesmo nome e namespace
| Tipo | Namespace |
|---|---|
| Cornerradius | Microsoft. UI. Xaml |
| Duração | Microsoft. UI. Xaml |
| DurationType | Microsoft. UI. Xaml |
| GridLength | Microsoft. UI. Xaml |
| Gridunittype | Microsoft. UI. Xaml |
| Espessura | Microsoft. UI. Xaml |
| GeneratorPosition | Microsoft.UI.Xaml.Controls.Primitives |
| Matriz | 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 |
Windows developer