/// <summary>
        /// GetChunk
        /// </summary>
        /// <returns>the next chunk</returns>
        public STAT_CHUNK GetChunk()
        {
            // Get the managed chunk
            ManagedChunk managedChunk = _implementation.GetChunk();

            if (managedChunk == null)
            {
                // End of chunks.

                if (ThrowOnEndOfChunks)
                {
                    // Throw exception.
                    throw new COMException(SR.Get(SRID.FilterEndOfChunks),
                                           (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS);
                }

                // Return STAT_CHUNK with idChunk as 0.

                STAT_CHUNK chunk = new STAT_CHUNK();
                chunk.idChunk = 0;
                return(chunk);
            }

            // Valid chunk. Return corresponding STAT_CHUNK.
            return(MarshalChunk(managedChunk));
        }
        internal static STAT_CHUNK MarshalChunk(ManagedChunk chunk)
        {
            STAT_CHUNK result = default(STAT_CHUNK);

            result.idChunk = chunk.ID;
            Invariant.Assert(chunk.BreakType >= CHUNK_BREAKTYPE.CHUNK_NO_BREAK && chunk.BreakType <= CHUNK_BREAKTYPE.CHUNK_EOC);
            result.breakType = chunk.BreakType;
            Invariant.Assert(chunk.Flags >= (CHUNKSTATE)0 && chunk.Flags <= (CHUNKSTATE.CHUNK_TEXT | CHUNKSTATE.CHUNK_VALUE | CHUNKSTATE.CHUNK_FILTER_OWNED_VALUE));
            result.flags          = chunk.Flags;
            result.locale         = chunk.Locale;
            result.idChunkSource  = chunk.ChunkSource;
            result.cwcStartSource = chunk.StartSource;
            result.cwcLenSource   = chunk.LenSource;
            IndexingFilterMarshaler.MarshalFullPropSpec(chunk.Attribute, ref result.attribute);
            return(result);
        }
        public STAT_CHUNK GetChunk()
        {
            ManagedChunk chunk = this._implementation.GetChunk();

            if (chunk != null)
            {
                return(IndexingFilterMarshaler.MarshalChunk(chunk));
            }
            if (this.ThrowOnEndOfChunks)
            {
                throw new COMException(SR.Get("FilterEndOfChunks"), -2147215616);
            }
            return(new STAT_CHUNK
            {
                idChunk = 0U
            });
        }
        /// <summary>
        /// GetChunk
        /// </summary>
        /// <returns>An interop STAT_CHUNK from a ManagedChunk</returns>
        internal static STAT_CHUNK MarshalChunk(ManagedChunk chunk)
        {
            STAT_CHUNK native = new STAT_CHUNK();

            native.idChunk = chunk.ID;
            Invariant.Assert(chunk.BreakType >= CHUNK_BREAKTYPE.CHUNK_NO_BREAK && chunk.BreakType <= CHUNK_BREAKTYPE.CHUNK_EOC);
            native.breakType = chunk.BreakType;
            Invariant.Assert(
                chunk.Flags >= 0
                &&
                chunk.Flags <= (CHUNKSTATE.CHUNK_TEXT | CHUNKSTATE.CHUNK_VALUE | CHUNKSTATE.CHUNK_FILTER_OWNED_VALUE));
            native.flags          = chunk.Flags;
            native.locale         = chunk.Locale;
            native.idChunkSource  = chunk.ChunkSource;
            native.cwcStartSource = chunk.StartSource;
            native.cwcLenSource   = chunk.LenSource;
            MarshalFullPropSpec(chunk.Attribute, ref native.attribute);

            return(native);
        }
        internal static STAT_CHUNK MarshalChunk(ManagedChunk chunk)
        {
            STAT_CHUNK native = new STAT_CHUNK();

            native.idChunk = chunk.ID;
            Invariant.Assert(chunk.BreakType >= CHUNK_BREAKTYPE.CHUNK_NO_BREAK && chunk.BreakType <= CHUNK_BREAKTYPE.CHUNK_EOC);
            native.breakType = chunk.BreakType;
            Invariant.Assert(    
                chunk.Flags >= 0 
                && 
                chunk.Flags <= (CHUNKSTATE.CHUNK_TEXT | CHUNKSTATE.CHUNK_VALUE | CHUNKSTATE.CHUNK_FILTER_OWNED_VALUE));
            native.flags = chunk.Flags;
            native.locale = chunk.Locale;
            native.idChunkSource = chunk.ChunkSource;
            native.cwcStartSource = chunk.StartSource;
            native.cwcLenSource = chunk.LenSource;
            MarshalFullPropSpec(chunk.Attribute, ref native.attribute);

            return native;
        }