IPropertySet Interface

Définition

Représente une collection de paires clé-valeur, corrélatant plusieurs autres interfaces de collection.

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)
Dérivé
Attributs
Implémente
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>

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (introduit dans v1.0)

Exemples

Cet exemple montre comment case activée pour un élément dans l’objet IPropertySet retourné par une propriété Windows Runtime. Plus précisément, il s’agit de la propriété CoreApplication.Properties . Cet extrait de code provient de l’exemple de client HTTP ControlChannelTrigger. Notez comment la version C# est castée en objet string,object> IDictionary< afin qu’elle puisse utiliser l’indexeur, tandis que la version des extensions de composant Visual C++ (C++/CX) utilise HasKey et Lookup. En règle générale, c’est tout ce que vous faites avec un objet IPropertySet que vous obtenez à partir des différentes propriétés Windows Runtime qui retournent le type : recherchez des clés spécifiques dans le jeu de propriétés, puis définissez une propriété d’application sur la valeur correspondante si elle existe.

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

Remarques

Cette interface est inhabituelle en ce qu’elle ne définit aucun nouveau membre. Au lieu de cela, il met en corrélation trois autres interfaces de collection afin qu’elles partagent les mêmes contraintes de paramètre de type :

Si vous castez un objet en IPropertySet (qui n’est pas générique), vous pouvez utiliser les méthodes combinées de ces trois interfaces basées sur l’utilisation de String pour clé, Object pour value. Pour une implémentation pratique, Windows Runtime utilise la classe PropertySet. Consultez la documentation des différents membres de PropertySet pour savoir comment utiliser ces méthodes une fois que vous avez été casté en tant qu’IPropertySet.

Dans de nombreux cas où une API Windows Runtime utilise un PropertySet comme valeur, il s’affiche en fait sous la forme IPropertySet dans les signatures. PropertySet peut être considéré comme l’implémentation pratique d’IPropertySet prête à être utilisée par le code d’application. Le code JavaScript peut traiter n’importe quelle valeur IPropertySet comme s’il implémentait les prototypes PropertySet . L’utilisation par type est le main scénario pour IPropertySet ; l’implémentation de l’interface dans le code de votre application est moins courante.

IPropertySet est également implémenté par la classe ValueSet . ValueSet est le type de valeur de plusieurs propriétés ContinuationData , qui activent la restauration de l’état lorsque les applications reprennent après l’appel d’une méthode AndContinue susceptible de désactiver l’application. ValueSet et toutes les propriétés ContinuationData et les méthodes AndContinue sont Windows Phone uniquement des API, car ce n’est que Windows Phone qui a ce comportement. Pour plus d’informations, consultez Comment continuer votre application du Store Windows Phone après l’appel d’une méthode AndContinue. La différence entre ValueSet et PropertySet est que l’implémentation ValueSet de méthodes telles que Insert applique que ses valeurs de propriété sont des types valeur.

Événements

MapChanged

Se produit lorsque la carte change.

(Hérité de IObservableMap<K,V>)

S’applique à

Voir aussi