ApplicationDataCompositeValue ApplicationDataCompositeValue ApplicationDataCompositeValue ApplicationDataCompositeValue Class

Represents related app settings that must be serialized and deserialized atomically.

Syntax

Declaration

public sealed class ApplicationDataCompositeValuepublic sealed class ApplicationDataCompositeValuePublic NotInheritable Class ApplicationDataCompositeValue

Remarks

A composite setting is serialized by inserting it into a settings map and deserialized by looking it up from the map.

Collection member lists

For JavaScript, ApplicationDataCompositeValue supports using an index to access items.

Examples

This example creates and reads a composite setting named exampleCompositeSetting.

Call the Remove(System.String) method to delete the exampleCompositeSetting setting when you have finished with it.

var applicationData = Windows.Storage.ApplicationData.current;

var localSettings = applicationData.localSettings;

// Create a composite setting

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

localSettings.values["exampleCompositeSetting"] = composite;

// Read data from a composite setting

var composite = localSettings.values["exampleCompositeSetting"];

if (!composite)
{
    // 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;

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

ApplicationDataCompositeValue^ 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");

Constructors summary

Creates and initializes a new, initially empty, instance of the object.

Properties summary

Gets the number of related application settings.

Methods summary

Removes all application settings previously inserted into the composite value object, returning the object to its empty state.

Retrieves an iterator to enumerate the settings in the composite value.

Returns a read-only snapshot of the contents of the composite value.

Determines whether there is an application setting with the specified key.

Creates or replaces an application setting.

Retrieves the specified application setting.

Removes the value with the specified key.

Events summary

Occurs when the map changes.

Constructors

  • ApplicationDataCompositeValue()
    ApplicationDataCompositeValue()
    ApplicationDataCompositeValue()
    ApplicationDataCompositeValue()

    Creates and initializes a new, initially empty, instance of the object.

    public ApplicationDataCompositeValue()public ApplicationDataCompositeValue()Public Function ApplicationDataCompositeValue() As

Properties

  • Size
    Size
    Size
    Size

    Gets the number of related application settings.

    public uint Size { get; }public uint Size { get; }Public ReadOnly Property Size As uint

    Property Value

    • uint
      uint
      uint
      uint

      The number of related settings.

Methods

  • Clear()
    Clear()
    Clear()
    Clear()

    Removes all application settings previously inserted into the composite value object, returning the object to its empty state.

    public void Clear()public void Clear()Public Function Clear() As void
  • First()
    First()
    First()
    First()

    Retrieves an iterator to enumerate the settings in the composite value.

    public IIterator<IKeyValuePair<string, object>> First()public IIterator<IKeyValuePair<string, object>> First()Public Function First() As IIterator( Of IKeyValuePairstring, object )

    Returns

    • The iterator.

    Remarks

    This iterator remains valid even if the composite value's contents are mutated. If the composite value is mutated, you must get a new iterator to see the updated contents of the composite value.

  • GetView()
    GetView()
    GetView()
    GetView()

    Returns a read-only snapshot of the contents of the composite value.

    public IMapView<string, object> GetView()public IMapView<string, object> GetView()Public Function GetView() As IMapView( Of string, object )

    Returns

    • The view of the composite value.

    Remarks

    If the composite value is mutated, you must get a new view to see the updated contents of the composite value.

  • HasKey(System.String)
    HasKey(System.String)
    HasKey(System.String)
    HasKey(System.String)

    Determines whether there is an application setting with the specified key.

    public bool HasKey(System.String)public bool HasKey(System.String)Public Function HasKey(System.String) As bool

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key.

    Returns

    • bool
      bool
      bool
      bool

      True if the key is found; otherwise false.

  • Insert(System.String,System.Object)
    Insert(System.String,System.Object)
    Insert(System.String,System.Object)
    Insert(System.String,System.Object)

    Creates or replaces an application setting.

    public bool Insert(System.String,System.Object)public bool Insert(System.String,System.Object)Public Function Insert(System.String,System.Object) As bool

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key of the setting to insert or replace.

    • value
      System.Object
      System.Object
      System.Object
      System.Object

      The setting value.

    Returns

    • bool
      bool
      bool
      bool

      True if an item with the specified key is an existing item and was replaced; otherwise, false.

  • Lookup(System.String)
    Lookup(System.String)
    Lookup(System.String)
    Lookup(System.String)

    Retrieves the specified application setting.

    public object Lookup(System.String)public object Lookup(System.String)Public Function Lookup(System.String) As object

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key of the setting.

    Returns

    • object
      object
      object
      object

      The value, if an item with the specified key exists. Use the HasKey method to determine whether the key exists.

  • Remove(System.String)
    Remove(System.String)
    Remove(System.String)
    Remove(System.String)

    Removes the value with the specified key.

    public void Remove(System.String)public void Remove(System.String)Public Function Remove(System.String) As void

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key of the value to remove.

Events

  • MapChanged
    MapChanged
    MapChanged
    MapChanged

    Occurs when the map changes.

    public event MapChangedEventHandler MapChangedpublic event MapChangedEventHandler MapChangedPublic Event MapChanged

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Storage.dll