Condividi tramite


ApplicationDataCompositeValue Classe

Definizione

Rappresenta le impostazioni dell'app correlate che devono essere serializzate e deserializzate in modo atomico.

public ref class ApplicationDataCompositeValue sealed : IIterable<IKeyValuePair<Platform::String ^, Platform::Object ^> ^>, IMap<Platform::String ^, Platform::Object ^>, IObservableMap<Platform::String ^, Platform::Object ^>, IPropertySet
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
class ApplicationDataCompositeValue final : IIterable<IKeyValuePair<winrt::hstring, IInspectable const&>>, IMap<winrt::hstring, IInspectable const&>, IObservableMap<winrt::hstring, IInspectable const&>, IPropertySet
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class ApplicationDataCompositeValue final : IIterable<IKeyValuePair<winrt::hstring, IInspectable const&>>, IMap<winrt::hstring, IInspectable const&>, IObservableMap<winrt::hstring, IInspectable const&>, IPropertySet
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
public sealed class ApplicationDataCompositeValue : IDictionary<string,object>, IEnumerable<KeyValuePair<string,object>>, IObservableMap<string,object>, IPropertySet
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class ApplicationDataCompositeValue : IDictionary<string,object>, IEnumerable<KeyValuePair<string,object>>, IObservableMap<string,object>, IPropertySet
function ApplicationDataCompositeValue()
Public NotInheritable Class ApplicationDataCompositeValue
Implements IDictionary(Of String, Object), IEnumerable(Of KeyValuePair(Of String, Object)), IObservableMap(Of String, Object), IPropertySet
Ereditarietà
Object Platform::Object IInspectable ApplicationDataCompositeValue
Attributi
Implementazioni
IMap<K,V> IDictionary<K,V> IMap<String,Object> IDictionary<String,Object> IMap<Platform::String,Platform::Object> IMap<winrt::hstring,IInspectable> IIterable<IKeyValuePair<K,V>> IEnumerable<KeyValuePair<K,V>> IIterable<IKeyValuePair<String,Object>> 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> IPropertySet

Requisiti Windows

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

Esempio

Questo esempio crea e legge un'impostazione composita denominata exampleCompositeSetting.

Chiamare il metodo Remove per eliminare l'impostazione al termine dell'operazione exampleCompositeSetting .

Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

// Create a composite setting

Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();
composite["intVal"] = 1;
composite["strVal"] = "string";

localSettings.Values["exampleCompositeSetting"] = composite;

// Read data from a composite setting

Windows.Storage.ApplicationDataCompositeValue composite = 
   (Windows.Storage.ApplicationDataCompositeValue)localSettings.Values["exampleCompositeSetting"];

if (composite == null)
{
   // No data
}
else
{
   // Access data in composite["intVal"] and composite["strVal"]
}

// Delete a composite setting

localSettings.Values.Remove("exampleCompositeSetting");
Windows::Storage::ApplicationDataContainer localSettings{
    Windows::Storage::ApplicationData::Current().LocalSettings() };
auto values{ localSettings.Values() };

{
    // Create a composite setting.
    Windows::Storage::ApplicationDataCompositeValue composite;
    composite.Insert(L"intVal", Windows::Foundation::PropertyValue::CreateInt32(1));
    composite.Insert(L"strVal", Windows::Foundation::PropertyValue::CreateString(L"string"));
    values.Insert(L"exampleCompositeSetting", composite);
}

{
    // Read data from a composite setting.
    Windows::Storage::ApplicationDataCompositeValue composite{ values.Lookup(L"exampleCompositeSetting").as<Windows::Storage::ApplicationDataCompositeValue>() };
    if (composite == nullptr)
    {
        // No data
    }
    else
    {
        int32_t one{ winrt::unbox_value<int32_t>(composite.Lookup(L"intVal")) };
        winrt::hstring hello{ winrt::unbox_value<winrt::hstring>(composite.Lookup(L"strVal")) };
    }
}

// Delete a composite setting.
values.Remove(L"exampleCompositeSetting");
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;

// Create a composite setting

ApplicationDataCompositeValue^ composite = ref new ApplicationDataCompositeValue();
composite->Insert("intVal", dynamic_cast<PropertyValue^>(PropertyValue::CreateInt32(1)));
composite->Insert("strVal", dynamic_cast<PropertyValue^>(PropertyValue::CreateString("string")));

auto values = localSettings->Values;
values->Insert("exampleCompositeSetting", composite);

// Read data from a composite setting

composite = safe_cast<ApplicationDataCompositeValue^>(localSettings->Values->Lookup("exampleCompositeSetting"));

if (composite == nullptr)
{
   // No data
}
else
{
   int one = safe_cast<IPropertyValue^>(composite->Lookup("intVal"))->GetInt32();
   String^ hello = safe_cast<String^>(composite->Lookup("strVal"));
}

// Delete a composite setting

values->Remove("exampleCompositeSetting");
Dim localSettings As Windows.Storage.ApplicationDataContainer = Windows.Storage.ApplicationData.Current.LocalSettings

' Create a composite setting

Dim composite As New Windows.Storage.ApplicationDataCompositeValue
composite("intVal") = 1
composite("strVal") = "string";

localSettings.Values("exampleCompositeSetting") = composite

' Read data from a composite setting

Dim composite As Windows.Storage.ApplicationDataCompositeValue = 
   CType(localSettings.Values("exampleCompositeSetting"), Windows.Storage.ApplicationDataCompositeValue)

If composite Is Nothing Then
   ' No data
Else
   ' Access data in composite("intVal") and composite("strVal")
End If

' Delete a composite setting

localSettings.Values.Remove("exampleCompositeSetting")

Commenti

Un'impostazione composita viene serializzata inserendola in una mappa delle impostazioni e deserializzata cercandola dalla mappa.

Elenchi di membri della raccolta

Per JavaScript, ApplicationDataCompositeValue supporta l'uso di un indice per accedere agli elementi.

Costruttori

ApplicationDataCompositeValue()

Crea e inizializza un nuovo, inizialmente vuoto, istanza dell'oggetto.

Proprietà

Size

Ottiene il numero di impostazioni dell'applicazione correlate.

Metodi

Clear()

Rimuove tutte le impostazioni dell'applicazione inserite in precedenza nell'oggetto valore composito, restituendo l'oggetto allo stato vuoto.

First()

Recupera un iteratore per enumerare le impostazioni nel valore composito.

GetView()

Restituisce uno snapshot di sola lettura del contenuto del valore composito.

HasKey(String)

Determina se è presente un'impostazione dell'applicazione con la chiave specificata.

Insert(String, Object)

Crea o sostituisce un'impostazione dell'applicazione.

Lookup(String)

Recupera l'impostazione dell'applicazione specificata.

Remove(String)

Rimuove il valore con la chiave specificata.

Eventi

MapChanged

Si verifica quando la mappa cambia.

Si applica a

Vedi anche