IPropertySet Interfaccia

Definizione

Rappresenta una raccolta di coppie chiave-valore, correlando diverse altre interfacce di raccolta.

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)
Derivato
Attributi
Implementazioni
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>

Requisiti Windows

Famiglia di dispositivi
Windows 10 (è stato introdotto in 10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (è stato introdotto in v1.0)

Esempio

In questo esempio viene illustrato come verificare la presenza di un elemento all'interno dell'oggetto IPropertySet restituito da una proprietà Windows Runtime. In particolare, si tratta della proprietà CoreApplication.Properties . Questo frammento di codice proviene dall'esempio di client HTTP ControlChannelTrigger. Si noti come la versione C# esegue il cast della stringa IDictionary<, oggetto> in modo che possa usare l'indicizzatore, mentre la versione delle estensioni del componente Visual C++ (C++/CX) usa HasKey e Lookup. In genere si tratta di tutte le operazioni eseguite con un oggetto IPropertySet ottenuto dalle varie proprietà Windows Runtime che restituiscono il tipo: cercare chiavi specifiche nel set di proprietà e quindi impostare alcune proprietà dell'app sul valore corrispondente, se esistente.

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

Commenti

Questa interfaccia è insolita in quanto non definisce nuovi membri. Correla invece tre altre interfacce di raccolta in modo che convidano gli stessi vincoli di parametro di tipo:

Se si esegue il cast di un oggetto a IPropertySet (che non è un generico), è possibile usare i metodi combinati di queste tre interfacce in base all'uso di String per chiave, Object per value. Per un'implementazione pratica, Windows Runtime usa la classe PropertySet. Vedere la documentazione per i vari membri di PropertySet per informazioni su come usare questi metodi dopo il cast come IPropertySet.

In molti casi in cui un'API Windows Runtime usa propertySet come valore, viene effettivamente visualizzata come IPropertySet nelle firme. PropertySet può essere considerata l'implementazione pratica di IPropertySet pronta per l'uso dal codice dell'app. Il codice JavaScript può considerare qualsiasi valore IPropertySet come se implementasse i prototipi PropertySet . L'utilizzo per tipo è lo scenario principale per IPropertySet; implementare effettivamente l'interfaccia nel codice dell'app è meno comune.

IPropertySet viene implementato anche dalla classe ValueSet . ValueSet è il tipo di valore di diverse proprietà ContinuationData , che consentono il ripristino dello stato quando le app riprendono dopo aver chiamato un metodo AndContinue che potrebbe disattivare l'app. ValueSet e tutte le proprietà ContinuationData e i metodi AndContinue sono Windows Phone solo API perché è solo Windows Phone che ha questo comportamento. Per altre info, vedi Come continuare l'app Windows Phone Store dopo aver chiamato un metodo AndContinue. La differenza tra ValueSet e PropertySet è che l'implementazione ValueSet di metodi come Insert impone che i valori delle proprietà siano tipi valore.

Eventi

MapChanged

Si verifica quando la mappa viene modificata.

(Ereditato da IObservableMap<K,V>)

Si applica a

Vedi anche