IPropertySet 介面

定義

表示索引鍵/值組的集合,與數個其他集合介面相互關聯。

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)
衍生
屬性
實作
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>

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.FoundationContract (已於 v1.0 引進)

範例

此範例示範如何檢查 Windows 執行階段 屬性所傳回之 IPropertySet 物件內的專案。 具體而言,這是來自 CoreApplication.Properties 屬性。 此程式碼片段來自 ControlChannelTrigger HTTP 用戶端範例。 請注意 C# 版本如何轉換成IDictionary < 字串,物件 >以便使用索引子,而 Visual C++ 元件延伸模組 (C++/CX) 版本會使用HasKeyLookup。 這通常是您使用從傳回類型的各種Windows 執行階段屬性取得的 IPropertySet 物件:尋找屬性集中的特定索引鍵,然後在存在時將某些應用程式屬性設定為對應的值。

// 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");
}

備註

這個介面不尋常,因為它不會定義任何新的成員。 相反地,它會相互關聯三個其他集合介面,讓它們共用相同的類型參數條件約束:

如果您將物件轉換成 IPropertySet (這不是泛型) 您可以使用這三個介面的合併方法,方法是根據使用 String 作為索引鍵、 Object for value。 對於實際實作,Windows 執行階段使用PropertySet類別。 請參閱 PropertySet 各種成員的檔,瞭解如何在轉換成 IPropertySet 之後使用這些方法。

在許多情況下,Windows 執行階段 API 會使用PropertySet做為值,實際上會在簽章中顯示為 IPropertySet。 PropertySet 可視為 IPropertySet 的實際實作,可供應用程式程式碼使用。 JavaScript 程式碼可以將任何 IPropertySet 值視為實作 PropertySet 原型。 依類型使用是 IPropertySet 的主要案例;實際上,在應用程式程式碼中實作 介面較不常見。

IPropertySet 也會由 ValueSet 類別實作。 ValueSet 是數個 ContinuationData 屬性的數值型別,可啟用應用程式在呼叫可能會停用應用程式的 AndContinue 方法之後繼續還原狀態。 ValueSet和所有ContinuationData屬性和AndContinue方法只會Windows Phone API,因為它只會Windows Phone具有此行為。 如需詳細資訊,請參閱如何在呼叫 AndContinue 方法之後繼續您的Windows Phone市集應用程式ValueSet 和 PropertySet之間的差異在於Insert之類的方法ValueSet實作會強制其屬性值是實值型別。

事件

MapChanged

發生于地圖變更時。

(繼承來源 IObservableMap<K,V>)

適用於

另請參閱