internal static MessageItem ItemBindAsMessage(StoreSession session, StoreId storeId, ItemBuilder.MapiMessageCreator mapiMessageCreator, ItemBindOption itemBindOption, ICollection <PropertyDefinition> propertiesToLoad)
        {
            ItemCreateInfo messageItemInfo = ItemCreateInfo.MessageItemInfo;

            propertiesToLoad = ItemBuilder.GetPropertiesToLoad(itemBindOption, messageItemInfo.Schema, propertiesToLoad);
            CoreItem    coreItem    = null;
            MessageItem messageItem = null;
            bool        flag        = false;
            MessageItem result;

            try
            {
                StoreObjectType storeObjectType = StoreObjectType.Message;
                coreItem    = ItemBuilder.CoreItemBind(session, storeId, mapiMessageCreator, itemBindOption, propertiesToLoad, ref storeObjectType);
                messageItem = (MessageItem)messageItemInfo.Creator(coreItem);
                flag        = true;
                result      = messageItem;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(messageItem);
                    Util.DisposeIfPresent(coreItem);
                }
            }
            return(result);
        }
        internal static T ItemBind <T>(StoreSession session, StoreId storeId, Schema expectedSchema, ItemBuilder.MapiMessageCreator mapiMessageCreator, ItemBindOption itemBindOption, ICollection <PropertyDefinition> propertiesToLoad) where T : Item
        {
            propertiesToLoad = ItemBuilder.GetPropertiesToLoad(itemBindOption, expectedSchema, propertiesToLoad);
            bool     flag     = false;
            CoreItem coreItem = null;
            Item     item     = null;
            T        t        = default(T);
            T        result;

            try
            {
                StoreObjectType storeObjectType = StoreObjectType.Unknown;
                coreItem = ItemBuilder.CoreItemBind(session, storeId, mapiMessageCreator, itemBindOption, propertiesToLoad, ref storeObjectType);
                ItemCreateInfo itemCreateInfo = ItemCreateInfo.GetItemCreateInfo(storeObjectType);
                item   = itemCreateInfo.Creator(coreItem);
                t      = item.DownCastStoreObject <T>();
                flag   = true;
                result = t;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(t);
                    Util.DisposeIfPresent(item);
                    Util.DisposeIfPresent(coreItem);
                }
            }
            return(result);
        }
        internal static T CreateNewItem <T>(StoreSession session, ItemCreateInfo itemCreateInfo, ItemBuilder.MapiMessageCreator mapiMessageCreator) where T : Item
        {
            T        t        = default(T);
            CoreItem coreItem = null;
            bool     flag     = false;
            T        result;

            try
            {
                coreItem = ItemBuilder.CreateNewCoreItem(session, itemCreateInfo, true, mapiMessageCreator);
                t        = (T)((object)itemCreateInfo.Creator(coreItem));
                flag     = true;
                result   = t;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(t);
                    Util.DisposeIfPresent(coreItem);
                }
            }
            return(result);
        }