internal static Restriction ConvertToMapiRestriction(Restriction restriction)
        {
            if (restriction == null)
            {
                return(null);
            }
            switch (restriction.RestrictionType)
            {
            case RestrictionType.And:
                return(Restriction.And(ConvertHelper.ConvertToMapiRestrictions(((CompositeRestriction)restriction).ChildRestrictions)));

            case RestrictionType.Or:
                return(Restriction.Or(ConvertHelper.ConvertToMapiRestrictions(((CompositeRestriction)restriction).ChildRestrictions)));

            case RestrictionType.Not:
                return(Restriction.Not(ConvertHelper.ConvertToMapiRestriction(((NotRestriction)restriction).ChildRestriction)));

            case RestrictionType.Content:
            {
                ContentRestriction contentRestriction = restriction as ContentRestriction;
                if (contentRestriction.PropertyValue == null)
                {
                    throw new NspiException(NspiStatus.InvalidParameter, "Null PropertyValue is not valid for ContentRestriction.");
                }
                return(Restriction.Content(ConvertHelper.ConvertToMapiPropTag(contentRestriction.PropertyTag), contentRestriction.PropertyTag.IsMultiValuedProperty, ConvertHelper.ConvertToMapiPropValue(contentRestriction.PropertyValue.Value), (ContentFlags)contentRestriction.FuzzyLevel));
            }

            case RestrictionType.Property:
            {
                PropertyRestriction propertyRestriction = restriction as PropertyRestriction;
                if (propertyRestriction.PropertyValue == null)
                {
                    throw new NspiException(NspiStatus.InvalidParameter, "Null PropertyValue is not valid for PropertyRestriction.");
                }
                return(Restriction.Property(ConvertHelper.ConvertToMapiRelOp(propertyRestriction.RelationOperator), ConvertHelper.ConvertToMapiPropTag(propertyRestriction.PropertyTag), propertyRestriction.PropertyTag.IsMultiValuedProperty, ConvertHelper.ConvertToMapiPropValue(propertyRestriction.PropertyValue.Value)));
            }

            case RestrictionType.CompareProps:
            {
                ComparePropsRestriction comparePropsRestriction = restriction as ComparePropsRestriction;
                return(Restriction.CompareProps(ConvertHelper.ConvertToMapiRelOp(comparePropsRestriction.RelationOperator), ConvertHelper.ConvertToMapiPropTag(comparePropsRestriction.Property1), ConvertHelper.ConvertToMapiPropTag(comparePropsRestriction.Property2)));
            }

            case RestrictionType.BitMask:
            {
                BitMaskRestriction bitMaskRestriction = restriction as BitMaskRestriction;
                return(Restriction.BitMask(ConvertHelper.ConvertToMapiRelBmr(bitMaskRestriction.BitMaskOperator), ConvertHelper.ConvertToMapiPropTag(bitMaskRestriction.PropertyTag), (int)bitMaskRestriction.BitMask));
            }

            case RestrictionType.Size:
            {
                SizeRestriction sizeRestriction = restriction as SizeRestriction;
                return(Restriction.PropertySize(ConvertHelper.ConvertToMapiRelOp(sizeRestriction.RelationOperator), ConvertHelper.ConvertToMapiPropTag(sizeRestriction.PropertyTag), (int)sizeRestriction.Size));
            }

            case RestrictionType.Exists:
            {
                ExistsRestriction existsRestriction = restriction as ExistsRestriction;
                return(Restriction.Exist(ConvertHelper.ConvertToMapiPropTag(existsRestriction.PropertyTag)));
            }

            case RestrictionType.SubRestriction:
            {
                SubRestriction subRestriction = restriction as SubRestriction;
                return(Restriction.Sub(ConvertHelper.ConvertToMapiPropTag(subRestriction.SubRestrictionType), ConvertHelper.ConvertToMapiRestriction(subRestriction.ChildRestriction)));
            }

            default:
                throw new NspiException(NspiStatus.InvalidParameter, string.Format("Invalid restriction type: {0}", restriction));
            }
        }