Property​Set Property​Set Property​Set Class

Definition

Represents a property set, which is a set of PropertyValue objects with string keys.

public sealed class PropertySet : IIterable, IMap, IObservableMap, IPropertySetpublic sealed class PropertySet : IEnumerable, IDictionary, IObservableMap, IPropertySetPublic NotInheritable Class PropertySet Implements IEnumerable, IDictionary, IObservableMap, IPropertySet
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (introduced v1)

Remarks

This class implements a map (the IMap; interface) with keys of type String and values of type PropertyValue. The PropertySet type enables various Windows Runtime APIs to return a collection of mixed values that can still be iterated or inspected using the common collection APIs of PropertySet, which match those of IMap;, IDictionary<TKey,TValue>, or JavaScript collection and enumeration techniques, depending on which language your app uses.

PropertyValue is a class that supports a large number of static Create* methods that create a deliberately untyped value from an input that's typically a value type or primitive (Boolean, numbers and so on) or an array of those values. Once one of the static PropertyValue methods is called, its return value can be treated as a PropertyValue instance (however the Create* methods technically return an Object if you look at the signatures).

However, you don't typically use a PropertySet in a way that requires you to fill the PropertyValue values in the set yourself. Instead, you typically get a filled-in PropertySet as a return value from a Windows Runtime API that's providing a collection where the value types within it might be mixed, but are still related to each other by origin or scenario. For example, the LocalSettings and RoamingSettings values that you get when you retrieve app data are of type ApplicationDataContainer, and each contains a PropertySet as its Values property value. When you interact with app data that's storing settings, you typically get the collection from ApplicationDataContainer.Values. Then you can:

  • iterate over the set using the appropriate iteration syntax
  • use HasKey /ContainsKey to verify the existence of a PropertyValue in the set
  • use Lookup or the Item indexer to retrieve an item once you know it exists

For scenarios like working with app data, when you have a PropertySet you have it by reference, so if you add items to the PropertySet using Add/Insert these items will be added to the app data, and removing items removes them from app data. All such changes are then shared through the app data mechanisms, if they're made to the RoamingSettings.

There are other Windows Runtime APIs that use a PropertySet value as a direct value rather than wrapped in another class like ApplicationDataContainer. For example, CoreApplication.Properties returns a PropertySet.

Various properties that report info from media and devices use PropertySet, for example PlayToReceiver.Properties. However, there are other media/devices property sets that don't use PropertySet and instead use MediaPropertySet, because the identifier for those properties is better represented when keyed as a GUID rather than a string.

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.

Collection member lists

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

Constructors

PropertySet() PropertySet() PropertySet()

Creates and initializes a new instance of the property set.

public PropertySet()public PropertySet()Public Sub New()
Attributes

Properties

Item[TKey] Item[TKey] Item[TKey]

Gets or sets the element with the specified key.

This member is not implemented in C++TValue this[TKey key] { get; set; }Property Item(key As TKey) As TValue
Parameters
key
TKey TKey TKey

The key of the element to get or set.

Value
TValue TValue TValue

The element with the specified key.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

System.Collections.Generic.KeyNotFoundException System.Collections.Generic.KeyNotFoundException System.Collections.Generic.KeyNotFoundException

The property is retrieved and key is not found.

System.NotSupportedException System.NotSupportedException System.NotSupportedException

The property is set and the System.Collections.Generic.IDictionary`2 is read-only.

See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

Keys Keys Keys

Gets an System.Collections.Generic.ICollection`1 containing the keys of the System.Collections.Generic.IDictionary`2.

This member is not implemented in C++ICollection<TKey> Keys { get; }ReadOnly Property Keys As ICollection(Of TKey)
Value
System.Collections.Generic.ICollection<TKey> System.Collections.Generic.ICollection<TKey> System.Collections.Generic.ICollection<TKey>

An System.Collections.Generic.ICollection`1 containing the keys of the object that implements System.Collections.Generic.IDictionary`2.

Attributes
See Also
System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>

Size Size Size

Gets the number of items contained in the property set.

public unsigned short Size { get; }This member is not implemented in C#This member is not implemented in VB.Net
Value
uint uint uint

The number of items in the property set.

Attributes

Values Values Values

Gets an System.Collections.Generic.ICollection`1 containing the values in the System.Collections.Generic.IDictionary`2.

This member is not implemented in C++ICollection<TValue> Values { get; }ReadOnly Property Values As ICollection(Of TValue)
Value
System.Collections.Generic.ICollection<TValue> System.Collections.Generic.ICollection<TValue> System.Collections.Generic.ICollection<TValue>

An System.Collections.Generic.ICollection`1 containing the values in the object that implements System.Collections.Generic.IDictionary`2.

Attributes
See Also
System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>System.Collections.Generic.ICollection<T>

Methods

Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue)

Adds an element with the provided key and value to the System.Collections.Generic.IDictionary`2.

This member is not implemented in C++void Add(TKey key, TValue value)Sub Add(key As TKey, value As TValue)
Parameters
key
TKey TKey TKey

The object to use as the key of the element to add.

value
TValue TValue TValue

The object to use as the value of the element to add.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

System.ArgumentException System.ArgumentException System.ArgumentException

An element with the same key already exists in the System.Collections.Generic.IDictionary`2.

System.NotSupportedException System.NotSupportedException System.NotSupportedException

The System.Collections.Generic.IDictionary`2 is read-only.

See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

Clear() Clear() Clear()

Removes all items from the property set.

public void Clear()This member is not implemented in C#This member is not implemented in VB.Net
Attributes

ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey)

Determines whether the System.Collections.Generic.IDictionary`2 contains an element with the specified key.

This member is not implemented in C++bool ContainsKey(TKey key)Function ContainsKey(key As TKey) As Boolean
Parameters
key
TKey TKey TKey

The key to locate in the System.Collections.Generic.IDictionary`2.

Returns
System.Boolean System.Boolean System.Boolean

true if the System.Collections.Generic.IDictionary`2 contains an element with the key; otherwise, false.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

First() First() First()

Returns an iterator to enumerate the items in the property set.

public IIterator<IKeyValuePair<string, object>> First()This member is not implemented in C#This member is not implemented in VB.Net
Returns

The iterator. The current position of the iterator is index 0, or the end of the property set if the property set is empty.

Attributes

GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through the collection.

This member is not implemented in C++IEnumerator<T> GetEnumerator()Function GetEnumerator As IEnumerator(Of T)
Returns
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T>

An enumerator that can be used to iterate through the collection.

Attributes
See Also
System.Collections.Generic.IEnumerator<T>System.Collections.Generic.IEnumerator<T>System.Collections.Generic.IEnumerator<T>

GetView() GetView() GetView()

Gets an immutable view of the property set.

public IMapView<string, object> GetView()This member is not implemented in C#This member is not implemented in VB.Net
Returns

The immutable view.

Attributes

HasKey(String) HasKey(String) HasKey(String)

Indicates whether the property set has an item with the specified key.

public PlatForm::Boolean HasKey(String key)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key.

Returns
bool bool bool

True if the property set has an item with the specified key; otherwise, false.

Attributes

Insert(String, Object) Insert(String, Object) Insert(String, Object)

Adds an item to the property set.

public PlatForm::Boolean Insert(String key, Object value)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key to insert.

value
System.Object System.Object System.Object

The value to insert.

Returns
bool bool bool

True if the method replaces a value that already exists for the key; false if this is a new key.

Attributes

Lookup(String) Lookup(String) Lookup(String)

Retrieves the value for the specified key.

public PlatForm::Object Lookup(String key)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key.

Returns
object object object

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

Attributes

Remove(TKey) Remove(TKey) Remove(TKey)

Removes the element with the specified key from the System.Collections.Generic.IDictionary`2.

This member is not implemented in C++bool Remove(TKey key)Function Remove(key As TKey) As Boolean
Parameters
key
TKey TKey TKey

The key of the element to remove.

Returns
System.Boolean System.Boolean System.Boolean

true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original System.Collections.Generic.IDictionary`2.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

System.NotSupportedException System.NotSupportedException System.NotSupportedException

The System.Collections.Generic.IDictionary`2 is read-only.

See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

Remove(String) Remove(String) Remove(String)

Removes an item from the property set.

public void Remove(String key)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
key
System.String System.String System.String

The key.

Attributes

Remarks

For the C# or Microsoft Visual Basic version of the Remove method, see Remove.

TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue)

Gets the value associated with the specified key.

This member is not implemented in C++bool TryGetValue(TKey key, out TValue value)Function TryGetValue(key As TKey, ByRef value As TValue) As Boolean
Parameters
key
TKey TKey TKey

The key whose value to get.

value
TValue TValue TValue

When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns
System.Boolean System.Boolean System.Boolean

true if the object that implements System.Collections.Generic.IDictionary`2 contains an element with the specified key; otherwise, false.

Attributes
Exceptions
System.ArgumentNullException System.ArgumentNullException System.ArgumentNullException

key is null.

Events

MapChanged MapChanged MapChanged

Occurs when the observable map has changed.

public event MapChangedEventHandler MapChangedpublic event MapChangedEventHandler MapChangedPublic Event MapChanged
Attributes