IPropertySet Antarmuka

Definisi

Mewakili kumpulan pasangan kunci-nilai, yang menghubungkan beberapa antarmuka koleksi lainnya.

public interface class IPropertySet : IIterable<IKeyValuePair<Platform::String ^, Platform::Object ^> ^>, IMap<Platform::String ^, Platform::Object ^>, IObservableMap<Platform::String ^, Platform::Object ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.FoundationContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(2319707551, 62694, 17441, 172, 249, 29, 171, 41, 134, 130, 12)]
/// [Windows.Foundation.Metadata.HasVariant]
struct IPropertySet : IIterable<IKeyValuePair<winrt::hstring, IInspectable const&>>, IMap<winrt::hstring, IInspectable const&>, IObservableMap<winrt::hstring, IInspectable const&>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.FoundationContract), 65536)]
[Windows.Foundation.Metadata.Guid(2319707551, 62694, 17441, 172, 249, 29, 171, 41, 134, 130, 12)]
[Windows.Foundation.Metadata.HasVariant]
public interface IPropertySet : IDictionary<string,object>, IEnumerable<KeyValuePair<string,object>>, IObservableMap<string,object>
Public Interface IPropertySet
Implements IDictionary(Of String, Object), IEnumerable(Of KeyValuePair(Of String, Object)), IObservableMap(Of String, Object)
Turunan
Atribut
Penerapan
IMap<K,V> IDictionary<K,V> IDictionary<String,Object> IMap<Platform::String,Platform::Object> IMap<winrt::hstring,IInspectable> IIterable<IKeyValuePair<K,V>> IEnumerable<KeyValuePair<K,V>> IEnumerable<KeyValuePair<String,Object>> IIterable<IKeyValuePair<Platform::String,Platform::Object>> IIterable<IKeyValuePair<winrt::hstring,IInspectable>> IObservableMap<String,Object> IObservableMap<Platform::String,Platform::Object> IObservableMap<winrt::hstring,IInspectable>

Persyaratan Windows

Rangkaian perangkat
Windows 10 (diperkenalkan dalam 10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (diperkenalkan dalam v1.0)

Contoh

Contoh ini memperlihatkan cara memeriksa item dalam objek IPropertySet yang dikembalikan oleh properti Windows Runtime. Secara khusus, ini berasal dari properti CoreApplication.Properties . Cuplikan kode ini berasal dari sampel klien HTTP ControlChannelTrigger. Perhatikan bagaimana versi C# ditransmisikan ke string IDictionary<, objek> sehingga dapat menggunakan pengindeks, sedangkan versi ekstensi komponen Visual C++ (C++/CX) menggunakan HasKey dan Lookup. Biasanya ini yang Anda lakukan dengan objek IPropertySet yang Anda dapatkan dari berbagai properti Windows Runtime yang mengembalikan jenis : cari kunci tertentu dalam kumpulan properti, lalu atur beberapa properti aplikasi ke nilai yang sesuai jika ada.

// In this example, the channel name has been hardcoded to lookup the property bag 
// for any previous contexts. The channel name may be used in more sophisticated ways 
// in case an app has multiple ControlChannelTrigger objects. 
string channelId = "channelOne";
if (((IDictionary<string, object>)CoreApplication.Properties).ContainsKey(channelId))
{
    try
    {
        AppContext appContext = null;
        lock(CoreApplication.Properties)
        {
            appContext = ((IDictionary<string, object>)CoreApplication.Properties)[channelId] as AppContext;
        }
        if (appContext != null && appContext.CommunicationInstance != null)
        {
            CommunicationModule communicationInstance = appContext.CommunicationInstance;

            // Clear any existing channels, sockets etc. 
            communicationInstance.Reset();

            // Create CCT enabled transport. 
            communicationInstance.SetUpTransport(communicationInstance.serverUri, GetType().Name);
        }
    }
    catch (Exception ex)
    {
        Diag.DebugPrint("Registering with CCT failed with: " + ex.ToString());
    }
}
else
{
    Diag.DebugPrint("Cannot find AppContext key channelOne");
}
// In this example, the channel name has been hardcoded to look up the property bag
// for any previous contexts. The channel name may be used in more sophisticated ways
// in case an app has multiple ControlChannelTrigger objects.
std::wstring channelId{ L"channelOne" };
if (CoreApplication::Properties().HasKey(channelId))
{
    try
    {
        auto appContext{ CoreApplication::Properties().Lookup(channelId).as<AppContext>() };
        if (appContext && appContext->CommunicationInstance())
        {
            CommunicationModule communicationInstance{ appContext->CommunicationInstance() };

            // Clear any existing channels, sockets etc.
            communicationInstance.Reset();

            // Create CCT enabled transport.
            communicationInstance.SetUpTransport(L"NetworkChangeTask");
        }
    }
    catch (winrt::hresult_error const& ex)
    {
        Diag::DebugPrint(L"Registering with CCT failed with: " + ex.message());
    }
}
else
{
    Diag::DebugPrint(L"Cannot find AppContext key channelOne");
}
// In this example, the channel name has been hardcoded to look up the property bag
// for any previous contexts. The channel name may be used in more sophisticated ways
// in case an app has multiple ControlChannelTrigger objects.
String^ channelId = "channelOne";
if (CoreApplication::Properties->HasKey(channelId))
{
    try
    {
        auto appContext = dynamic_cast<AppContext^>(CoreApplication::Properties->Lookup(channelId));
        if (appContext != nullptr && appContext->CommunicationInstance != nullptr)
        {
            CommunicationModule^ communicationInstance = appContext->CommunicationInstance;

            // Clear any existing channels, sockets etc. 
            communicationInstance->Reset();

            // Create CCT enabled transport 
            communicationInstance->SetUpTransport("NetworkChangeTask");
        }
    }
    catch (Exception^ ex)
    {
        Diag::DebugPrint("Registering with CCT failed with: " + ex->Message);
    }
}
else
{
    Diag::DebugPrint("Cannot find AppContext key channelOne");
}

Keterangan

Antarmuka ini tidak biasa karena tidak menentukan anggota baru. Sebaliknya, ini menghubungkan tiga antarmuka koleksi lainnya sehingga mereka memiliki batasan parameter jenis yang sama:

Jika Anda mentransmisikan objek ke IPropertySet (yang bukan generik), Anda kemudian dapat menggunakan metode gabungan dari ketiga antarmuka ini berdasarkan penggunaan String untuk kunci, Objek untuk nilai. Untuk implementasi praktis, Windows Runtime menggunakan kelas PropertySet . Lihat dokumentasi untuk berbagai anggota PropertySet untuk mempelajari cara menggunakan metode tersebut setelah Anda melakukan transmisi sebagai IPropertySet.

Dalam banyak kasus di mana WINDOWS Runtime API menggunakan PropertySet sebagai nilai, itu benar-benar ditampilkan sebagai IPropertySet di tanda tangan. PropertySet dapat dianggap sebagai implementasi praktis IPropertySet yang siap digunakan oleh kode aplikasi. Kode JavaScript dapat memperlakukan nilai IPropertySet apa pun seolah-olah mengimplementasikan prototipe PropertySet . Penggunaan berdasarkan jenis adalah skenario utama untuk IPropertySet; benar-benar mengimplementasikan antarmuka dalam kode aplikasi Anda kurang umum.

IPropertySet juga diimplementasikan oleh kelas ValueSet . ValueSet adalah jenis nilai dari beberapa properti ContinuationData , yang memungkinkan pemulihan status saat aplikasi dilanjutkan setelah memanggil metode AndContinue yang mungkin menonaktifkan aplikasi. ValueSet dan semua properti ContinuationData dan metode AndContinue adalah API khusus Windows Phone karena hanya Windows Phone yang memiliki perilaku ini. Untuk informasi selengkapnya, lihat Cara melanjutkan aplikasi Windows Phone Store Anda setelah memanggil metode AndContinue. Perbedaan antara ValueSet dan PropertySet adalah bahwa implementasi ValueSet dari metode seperti Insert memberlakukan bahwa nilai propertinya adalah jenis nilai.

Acara

MapChanged

Terjadi ketika peta berubah.

(Diperoleh dari IObservableMap<K,V>)

Berlaku untuk

Lihat juga