ItemFieldDictionary 类

表示一个项及其关联字段。

命名空间: Microsoft.Synchronization.SimpleProviders
程序集: Microsoft.Synchronization.SimpleProviders(在 microsoft.synchronization.simpleproviders.dll 中)

语法

声明
<DefaultMemberAttribute("Item")> _
Public Class ItemFieldDictionary
    Implements IDictionary(Of UInteger, ItemField), ICollection(Of KeyValuePair(Of UInteger, ItemField)), _
    IEnumerable(Of KeyValuePair(Of UInteger, ItemField)), IEnumerable
用法
Dim instance As ItemFieldDictionary
[DefaultMemberAttribute("Item")] 
public class ItemFieldDictionary : IDictionary<uint,ItemField>, ICollection<KeyValuePair<uint,ItemField>>, 
    IEnumerable<KeyValuePair<uint,ItemField>>, IEnumerable
[DefaultMemberAttribute(L"Item")] 
public ref class ItemFieldDictionary : IDictionary<unsigned int, ItemField^>, ICollection<KeyValuePair<unsigned int, ItemField^>>, 
    IEnumerable<KeyValuePair<unsigned int, ItemField^>>, IEnumerable
/** @attribute DefaultMemberAttribute("Item") */ 
public class ItemFieldDictionary implements IDictionary<UInt32,ItemField>, 
    ICollection<KeyValuePair<UInt32,ItemField>>, IEnumerable<KeyValuePair<UInt32,ItemField>>, IEnumerable
DefaultMemberAttribute("Item") 
public class ItemFieldDictionary implements IDictionary<uint,ItemField>, 
    ICollection<KeyValuePair<uint,ItemField>>, IEnumerable<KeyValuePair<uint,ItemField>>, IEnumerable

备注

ItemFieldDictionary 对象由许多简单提供程序方法用来存储和传递 ItemField 对象,这些对象可在将变更应用于目标时标识项。

示例

下面的代码示例演示 EnumerateItems 方法的实现,该方法适用于在内存内存储区中存储项的示例应用程序。CreateItemFieldDictionary 方法是一个示例方法,它为存储区中的每个项创建和返回 ItemFieldDictionary 对象。若要在完整应用程序的上下文中查看此代码,请参见"Sync101 using Simple Sync Provider" 应用程序(可从 Sync Framework SDK 和 Code Gallery 获得)。

public override void EnumerateItems(FullEnumerationContext context)
{
    List<ItemFieldDictionary> items = new List<ItemFieldDictionary>();
    foreach (ulong id in _store.Ids)
    {
        items.Add(_store.CreateItemFieldDictionary(id));
    }
    context.ReportItems(items);
}
public ItemFieldDictionary CreateItemFieldDictionary(ulong id)
{
    ItemFieldDictionary itemFields = null;

    if (_store.ContainsKey(id))
    {
        itemFields = new ItemFieldDictionary();
        itemFields.Add(new ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_ID, typeof(ulong), id));
        itemFields.Add(new ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), _store[id].TimeStamp));
    }
    else
    {
        throw new Exception("Item does not exist in store");
    }

    return itemFields;
}
Public Overrides Sub EnumerateItems(ByVal context As FullEnumerationContext)
    Dim items As New List(Of ItemFieldDictionary)()
    For Each id As ULong In _store.Ids
        items.Add(_store.CreateItemFieldDictionary(id))
    Next
    context.ReportItems(items)
End Sub
Public Function CreateItemFieldDictionary(ByVal id As ULong) As ItemFieldDictionary
    Dim itemFields As ItemFieldDictionary = Nothing

    If _store.ContainsKey(id) Then
        itemFields = New ItemFieldDictionary()
        itemFields.Add(New ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_ID, GetType(ULong), id))
        itemFields.Add(New ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_TIMESTAMP, GetType(ULong), _store(id).TimeStamp))
    Else
        Throw New Exception("Item does not exist in store")
    End If

    Return itemFields
End Function

继承层次结构

System.Object
  Microsoft.Synchronization.SimpleProviders.ItemFieldDictionary

线程安全

此类型的所有公共静态(在 Visual Basic 中共享 )成员都是线程安全的。不保证任何实例成员的线程安全。

请参阅

参考

ItemFieldDictionary 成员
Microsoft.Synchronization.SimpleProviders 命名空间