ItemFieldDictionary Class

Represents an item and its associated fields.

System.Object
  Microsoft.Synchronization.SimpleProviders.ItemFieldDictionary

Namespace:  Microsoft.Synchronization.SimpleProviders
Assembly:  Microsoft.Synchronization.SimpleProviders (in Microsoft.Synchronization.SimpleProviders.dll)

'Declaration
Public Class ItemFieldDictionary _
	Implements IDictionary(Of UInteger, ItemField),  _
	ICollection(Of KeyValuePair(Of UInteger, ItemField)), IEnumerable(Of KeyValuePair(Of UInteger, ItemField)),  _
	IEnumerable
'Usage
Dim instance As ItemFieldDictionary

The ItemFieldDictionary type exposes the following members.

  NameDescription
Public methodItemFieldDictionaryInitializes a new instance of the ItemFieldDictionary class.
Public methodItemFieldDictionary(IEnumerable(Of ItemField))Initializes a new instance of the ItemFieldDictionary class that contains a collection of ItemField objects.
Top

  NameDescription
Public propertyCountGets the number of ItemField objects in the ItemFieldDictionary collection.
Public propertyIsReadOnlyIndicates whether a value the ItemFieldDictionary collection is read-only.
Public propertyItemGets or sets the ItemField object that corresponds to the specified key.
Public propertyKeysGets a collection of the keys that are contained in the ItemFieldDictionary collection.
Public propertyValuesGets a collection of the values that are contained in the ItemFieldDictionary collection.
Top

  NameDescription
Public methodAdd(KeyValuePair(Of UInt32, ItemField))Adds an ItemField object to the ItemFieldDictionary collection.
Public methodAdd(ItemField)Adds an ItemField object to the ItemFieldDictionary collection.
Public methodAdd(UInt32, ItemField)Adds an ItemField object to the ItemFieldDictionary collection.
Public methodClearRemoves all ItemField objects from the ItemFieldDictionary collection.
Public methodContainsIndicates whether an ItemField object is contained in the ItemFieldDictionary collection.
Public methodContainsKeyIndicates whether the ItemFieldDictionary collection contains an ItemField object with the specified key.
Public methodCopyToCopies the elements of the ItemFieldDictionary collection to the specified array.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetEnumeratorReturns an IEnumerator object that enables you to iterate through the ItemFieldDictionary collection.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodRemove(KeyValuePair(Of UInt32, ItemField))Removes the specified ItemField object from the ItemFieldDictionary collection.
Public methodRemove(UInt32)Removes the ItemField object with the specified key from the ItemFieldDictionary collection.
Public methodToString (Inherited from Object.)
Public methodTryGetValueGets the value associated with the specified key.
Top

  NameDescription
Explicit interface implemetationPrivate methodIEnumerable(Of KeyValuePair(Of UInt32, ItemField)).GetEnumeratorReturns an IEnumerator object that enables you to iterate through the ItemFieldDictionary collection.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an IEnumerator object that enables you to iterate through the ItemFieldDictionary collection.
Top

ItemFieldDictionary objects are used by many of the simple provider methods to store and pass the ItemField objects that identify items when changes are applied to a destination.

The following code examples show an implementation of the EnumerateItems method for a sample application that stores items in an in-memory store. The CreateItemFieldDictionary method is a sample method that creates and returns an ItemFieldDictionary object for each item in the store. To view this code in the context of a complete application, see the "Sync101 using Simple Sync Provider" application that is available in the Sync Framework SDK and from 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


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: