Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. 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 .NET em aplicações de ambiente de trabalho que visam .NET 6 (ou versões posteriores). Nestas aplicações, o Visual Studio IntelliSense mostra o tipo .NET em vez do tipo Windows Runtime. Por exemplo, se um método Windows Runtime tomar um parâmetro do tipo IVector<string>, então o IntelliSense mostra um parâmetro do tipo IList<string>. De forma semelhante, num componente WinRT criado com C#/WinRT, utiliza-se o tipo .NET nas assinaturas dos membros. Quando usa C#/WinRT para gerar um componente Windows Runtime, o tipo .NET é traduzido para o tipo WinRT correspondente.
Os mapeamentos de tipos personalizados C#/WinRT são categorizados por tipos no SDK Windows ou em WinUI 3 (o WinUI faz parte do SDK de Aplicações Windows). Os tipos WinRT para mapeamentos do Windows SDK estão sob os espaços de nomes Windows.*, e os tipos WinRT para mapeamentos do WinUI estão sob os espaços de nomes Microsoft.UI.Xaml.*. Há dois motivos para mapeamentos de tipo personalizados que C#/WinRT faz para tipos WinRT:
Tipos WinRT que correspondem a tipos .NET com nomes e/ou espaços de nomes diferentes. Estes mapeamentos personalizados servem 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 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 possuem o mesmo nome de namespace e nome de tipo em 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 dos campos e requerem tipos auxiliares, que o .NET oculta. As versões .NET destas estruturas têm propriedades e métodos que fornecem a funcionalidade dos tipos auxiliares ocultos (por exemplo, Windows. UI. Cor).
Observação
Para uma lista de mapeamentos entre tipos WinRT e .NET no contexto de aplicações UWP, consulte mapeamentos de tipos do Windows Runtime no .NET.
Mapeamentos para tipos de WinRT no SDK do Windows
Tipos com um nome e/ou namespace diferente
| Tipo/namespace do WinRT | Tipo/espaço de nomes .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) | T< nullable> (System) |
| TimeSpan (Windows.Foundation) | TimeSpan (Sistema) |
| Uri (Windows.Foundation) | Uri (Sistema) |
| IIterable<T> (Windows.Foundation.Collections) | IEnumerável<T> (System.Collections.Generic) |
| IIterator<T> (Windows.Foundation.Collections) | IEnumerator<T> (System.Collections.Generic) |
| IMap<K,V> (Windows. Fundação. Coleções) | IDictionary<TKey,TValue> (System.Collections.Generic) |
| IMapView<K,V> (Windows. Fundação. Coleções) | IReadOnlyDictionary<TKey,TValue> (System.Collections.Generic) |
| IKeyValuePair<K,V> (Windows.Foundation.Collections) | KeyValuePair<TKey,TValue> (Sistema.Coleções.Genérico) |
| 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) |
| Vector2 (Windows. Foundation.Numerics) | Vetor2 (System.Numerics) |
| Vector3 (Windows. Foundation.Numerics) | Vetor3 (System.Numerics) |
| Vector4 (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 |
Windows developer