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<string,object> にキャストしてインデクサーを使用できるようにする方法に注意してください。一方、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");
}

注釈

このインターフェイスは、新しいメンバーを定義しないという点では珍しいです。 代わりに、同じ型パラメーター制約を共有するような他の 3 つのコレクション インターフェイスを関連付けます。

オブジェクトを IPropertySet (ジェネリックではない) にキャストする場合は、キーに String 、値に Object を使用することに基づいて、これら 3 つのインターフェイスの結合メソッドを使用できます。 実際に実装するために、Windows ランタイムは PropertySet クラスを使用します。 IPropertySet としてキャストした後でこれらのメソッドを使用する方法については、PropertySet のさまざまなメンバーのドキュメントを参照してください。

Windows ランタイム API が PropertySet を値として使用する多くの場合、実際にはシグネチャに IPropertySet として表示されます。 PropertySet は、アプリ コードで使用できる IPropertySet の実際的な実装と見なすことができます。 JavaScript コードでは、任意の IPropertySet 値を PropertySet プロトタイプを実装したかのように処理できます。 種類別の使用法は、IPropertySet のメインシナリオです。実際にアプリ コードにインターフェイスを実装することはあまり一般的ではありません。

IPropertySet は、 ValueSet クラスによっても実装されます。 ValueSet は、複数の ContinuationData プロパティの値型です。これにより、アプリを非アクティブ化する AndContinue メソッドを呼び出した後にアプリが再開されたときに状態を復元できます。 ValueSet プロパティと、すべての ContinuationData プロパティと AndContinue メソッドは、この動作を持つWindows Phoneのみであるため、WINDOWS PHONE API のみです。 詳細については、「AndContinue メソッドを呼び出した後にWindows Phone ストア アプリを続行する方法」を参照してください。 ValueSetPropertySet の違いは、Insert などのメソッドの ValueSet 実装によって、そのプロパティ値が値型であることが強制される点です。

イベント

MapChanged

マップが変更されたときに発生します。

(継承元 IObservableMap<K,V>)

適用対象

こちらもご覧ください