I​Property​Set I​Property​Set I​Property​Set Interface

Definition

Represents a collection of key-value pairs, correlating several other collection interfaces.

public interface IPropertySetpublic interface IPropertySetPublic Interface IPropertySet
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (introduced v1)

Remarks

This interface is unusual in that it doesn't define any new members. Instead, it correlates three other collection interfaces such that they share the same type parameter constraints:

If you cast an object to IPropertySet (which isn't a generic) you can then use the combined methods of these three interfaces based on using String for key, Object for value. For a practical implementation, Windows Runtime uses the PropertySet class. See the documentation for various members of PropertySet to learn how to use those methods once you cast as IPropertySet.

In many cases where a Windows Runtime API uses a PropertySet as a value, it's actually shown as IPropertySet in the signatures. PropertySet can be considered the practical implementation of IPropertySet that's ready for use by app code. JavaScript code can treat any IPropertySet value as if it implemented the PropertySet prototypes. Usage by type is the main scenario for IPropertySet; actually implementing the interface in your app code is less common.

IPropertySet is also implemented by the ValueSet class. ValueSet is the value type of several ContinuationData properties, which enable restoring state when apps resume after calling an AndContinue method that might deactivate the app. ValueSet and all the ContinuationData properties and AndContinue methods are Windows Phone only APIs because it's only Windows Phone that has this behavior. For more info, see How to continue your after calling an AndContinue method. The difference between ValueSet and PropertySet is that the ValueSet implementation of methods like Insert /Add enforces that its property values are value types.

Examples

This example shows how to check for an item within the IPropertySet object returned by a Windows Runtime property. Specifically, this is from the CoreApplication.Properties property. This code snippet comes from the ControlChannelT​rigger HTTP client sample. Note how the C# version casts to IDictionary<string,object> so that it can use the indexer, whereas the Visual C++ component extensions (C++/CX) version uses HasKey and Lookup. Typically this is all you do with an IPropertySet object that you get from the various Windows Runtime properties that return the type: look for specific keys in the property set, and then set some app property to the corresponding value if it exists.

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