IPropertySet 接口

定义

表示键值对的集合,将其他几个集合接口关联起来。

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)
派生
属性
实现
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>

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.FoundationContract (在 v1.0 中引入)

示例

此示例演示如何检查 Windows 运行时属性返回的 IPropertySet 对象中的项。 具体而言,这是来自 CoreApplication.Properties 属性。 此代码片段来自 ControlChannelTrigger HTTP 客户端示例。 请注意 C# 版本如何转换为 IDictionary<字符串、对象>,以便可以使用索引器,而 Visual C++ 组件扩展(C++/CX)版本使用 HasKeyLookup。 通常,这是你使用从返回类型的各种 Windows 运行时属性获取的 IPropertySet 对象所做的一切:查找属性集中的特定键,然后将某些应用属性设置为相应的值(如果存在)。

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

注解

此接口异常,因为它未定义任何新成员。 相反,它会关联其他三个集合接口,以便它们共享相同的类型参数约束:

如果将对象强制转换为 IPropertySet(不是泛型),则可以根据键的 String,使用这三个接口的组合方法,Object 作为值。 对于实际实现,Windows 运行时使用 PropertySet 类。 请参阅 PropertySet 的各个成员的文档,了解如何在强制转换为 IPropertySet 后使用这些方法。

在许多情况下,Windows 运行时 API 使用 PropertySet 作为值,它实际上在签名中显示为 IPropertySet。 PropertySet 可被视为可供应用代码使用的 IPropertySet 的实际实现。 JavaScript 代码可以像实现 PropertySet 原型一样对待任何 IPropertySet 值。 按类型使用是 IPropertySet 的主要方案;实际上,在应用代码中实现接口不太常见。

IPropertySet 也由 ValueSet 类实现。 ValueSet 是多个 ContinuationData 属性的值类型,可在调用可能停用应用的 AndContinue 方法后恢复应用时启用还原状态。 ValueSet 以及所有 ContinuationData 属性和 AndContinue 方法仅Windows Phone API,因为它仅Windows Phone具有此行为。 有关详细信息,请参阅 如何在调用 AndContinue 方法后继续Windows Phone应用商店应用。 ValueSetPropertySet 之间的区别在于,Insert 等方法的 ValueSet 实现强制其属性值为值类型。

事件

MapChanged

地图更改时发生。

(继承自 IObservableMap<K,V>)

适用于

另请参阅