Dela via


PropertySet Class

Definition

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

public ref class PropertySet 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.FoundationContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.FoundationContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PropertySet final : IIterable<IKeyValuePair<winrt::hstring, IInspectable const&>>, IMap<winrt::hstring, IInspectable const&>, IObservableMap<winrt::hstring, IInspectable const&>, IPropertySet
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.FoundationContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.FoundationContract")]
class PropertySet 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.FoundationContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.FoundationContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PropertySet : IDictionary<string,object>, IEnumerable<KeyValuePair<string,object>>, IObservableMap<string,object>, IPropertySet
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.FoundationContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.FoundationContract")]
public sealed class PropertySet : IDictionary<string,object>, IEnumerable<KeyValuePair<string,object>>, IObservableMap<string,object>, IPropertySet
function PropertySet()
Public NotInheritable Class PropertySet
Implements IDictionary(Of String, Object), IEnumerable(Of KeyValuePair(Of String, Object)), IObservableMap(Of String, Object), IPropertySet
Inheritance
Object Platform::Object IInspectable PropertySet
Attributes
Implements
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

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.FoundationContract (introduced in v1.0)

Remarks

This class implements a map (the IMap<K,V> 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<K,V>, 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()

Creates and initializes a new instance of the property set.

Properties

Size

Gets the number of items contained in the property set.

Methods

Clear()

Removes all items from the property set.

First()

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

GetView()

Gets an immutable view of the property set.

HasKey(String)

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

Insert(String, Object)

Adds an item to the property set.

Lookup(String)

Retrieves the value for the specified key.

Remove(String)

Removes an item from the property set.

Events

MapChanged

Occurs when the observable map has changed.

Applies to

See also