Partilhar via


Mapeamentos .NET de tipos WinRT em C#/WinRT

Este artigo lista os mapeamentos que o C#/WinRT faz entre tipos do Tempo de Execução do Windows (WinRT) e tipos .NET em aplicativos da área de trabalho destinados ao .NET 6 (ou posterior). Nesses aplicativos, o Visual Studio IntelliSense mostra o tipo .NET em vez do tipo do Tempo de Execução do Windows. Por exemplo, se um método do Tempo de Execução do Windows usar um parâmetro do tipo IVector<string>, o IntelliSense mostrará 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 do Tempo de Execução do Windows, 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 (WinUI 3 faz parte do Windows App SDK). Os tipos WinRT para mapeamentos do SDK do Windows vivem sob os namespaces Windows.* e os tipos WinRT para mapeamentos WinUI 3 vivem sob os namespaces Microsoft.UI.Xaml.*. Há dois motivos para mapeamentos de tipo personalizados que C#/WinRT faz para tipos WinRT:

  • Tipos WinRT que mapeiam para tipos .NET com um nome e/ou namespace diferente. Esses mapeamentos personalizados são para mapear tipos WinRT para tipos equivalentes .NET existentes. Há também casos em que o mapeamento é para um tipo diferente (por exemplo, um tipo de valor mapeia para um tipo de classe).

  • Tipos WinRT que correspondem a tipos .NET com o mesmo nome e espaço de nomes. 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 além de campos e exigem tipos auxiliares, que o .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.Color).

Observação

Para obter uma lista de mapeamentos entre tipos WinRT e .NET no contexto de aplicativos UWP, consulte mapeamentos .NET de tipos WinRT no UWP.

Mapeamentos para tipos WinRT no SDK do Windows

Tipos com um nome e/ou namespace diferente

Tipo/namespace do WinRT Tipo/namespace .NET
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 (Sistema)
IReference<T> (Windows.Foundation) Nullable<T> (System)
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 (Sistema)
AttributeUsageAttribute (Windows.Foundation.Metadata) AttributeUsageAttribute (Sistema)
Matrix3x2 (Windows.Foundation.Numerics) Matrix3x2 (System.Numerics)
Matrix4x4 (Windows.Foundation.Numerics) Matrix4x4 (System.Numerics)
Plano (Windows.Foundation.Numerics) Plano (System.Numerics)
Quaternion (Windows.Foundation.Numerics) Quatérnio (System.Numerics)
Vetor2 (Windows.Foundation.Numerics) Vetor2 (System.Numerics)
Vetor3 (Windows.Foundation.Numerics) Vetor3 (System.Numerics)
Vetor4 (Windows.Foundation.Numerics) Vetor4 (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 Espaço de nomes
IPropertyValue Windows.Foundation
IReferenceArray<T> Windows.Foundation
Ponto Windows.Foundation
Rect Windows.Foundation
Tamanho Windows.Foundation
Cor Windows.UI
TipoTipo: Windows.UI.Xaml.Interop

Mapeamentos para tipos WinRT no WinUI

Tipos com um nome e/ou namespace diferente

Tipo/namespace do WinRT Tipo/espaço de nomes .NET
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 (Sistema)

Tipos com o mesmo nome e namespace

Tipo Espaço de nomes
Raio de canto Microsoft.UI.Xaml
Duração Microsoft.UI.Xaml
TipoDeDuração Microsoft.UI.Xaml
GridLength Microsoft.UI.Xaml
TipoDeUnidadeDeGrelha Microsoft.UI.Xaml
Espessura Microsoft.UI.Xaml
Posição do Gerador Microsoft.UI.Xaml.Controls.Primitives
Matriz Microsoft.UI.Xaml.Media
KeyTime Microsoft.UI.Xaml.Media.Animation
RepeatBehavior Microsoft.UI.Xaml.Media.Animation
TipoDeComportamentoDeRepetição Microsoft.UI.Xaml.Media.Animation
Matrix3D (Microsoft.UI.Xaml.Media.Media3D