/// <summary>
        /// Get the existing sync state for this item, if it exists and is of the appropriate
        /// type, else null.
        /// </summary>
        /// <remarks>Outlook items are not true objects and don't have a common superclass,
        /// so we have to use this rather clumsy overloading.</remarks>
        /// <param name="contact">The item.</param>
        /// <returns>The appropriate sync state, or null if none.</returns>
        /// <exception cref="UnexpectedSyncStateClassException">if the sync state found is not of the expected class (shouldn't happen).</exception>
        public ContactSyncState GetSyncState(Outlook.ContactItem contact)
        {
            SyncState result;

            try
            {
                result = this.byOutlookId.ContainsKey(contact.EntryID) ? this.byOutlookId[contact.EntryID] : null;
                CrmId crmId = CheckForDuplicateSyncState(result, contact.GetCrmId());

                if (CrmId.IsValid(crmId))
                {
                    if (result == null && this.byCrmId.ContainsKey(crmId))
                    {
                        result = this.byCrmId[crmId];
                    }
                    else if (result != null && this.byCrmId.ContainsKey(crmId) == false)
                    {
                        this.byCrmId[crmId] = result;
                        result.CrmEntryId   = crmId;
                    }
                }

                if (result != null && result as ContactSyncState == null)
                {
                    throw new UnexpectedSyncStateClassException("ContactSyncState", result);
                }
            }
            catch (COMException)
            {
                // dead item passed.
                result = null;
            }

            return(result as ContactSyncState);
        }
        /// <summary>
        /// Create an appropriate sync state for an contact item.
        /// </summary>
        /// <remarks>Outlook items are not true objects and don't have a common superclass,
        /// so we have to use this rather clumsy overloading.</remarks>
        /// <param name="contact">The item.</param>
        /// <returns>An appropriate sync state.</returns>
        private ContactSyncState CreateSyncState(Outlook.ContactItem contact)
        {
            CrmId            crmId = contact.GetCrmId();
            ContactSyncState result;

            if (CrmId.IsValid(crmId) && this.byCrmId.ContainsKey(crmId) && this.byCrmId[crmId] != null)
            {
                result = CheckUnexpectedFoundState <Outlook.ContactItem, ContactSyncState>(contact, crmId);
            }
            else
            {
                result = this.SetByOutlookId <ContactSyncState>(contact.EntryID,
                                                                new ContactSyncState(contact, crmId,
                                                                                     ParseDateTimeFromUserProperty(contact.UserProperties[ModifiedDatePropertyName])));
            }

            if (result != null && CrmId.IsValid(crmId))
            {
                this.byCrmId[crmId] = result;
            }

            return(result);
        }