示例#1
0
        static T ReadTableIfExists <T>(TableEntryCollection tables, BinaryReader reader, T resultTable)
            where T : TableEntry
        {
            TableEntry found;

            if (tables.TryGetTable(resultTable.Name, out found))
            {
                //found table name
                //check if we have read this table or not
                if (found is UnreadTableEntry)
                {
                    //set header before actal read
                    resultTable.Header = found.Header;
                    resultTable.LoadDataFrom(reader);
                    //then reaplce
                    tables.ReplaceTable(resultTable);
                    return(resultTable);
                }
                else
                {
                    //we have read this table
                    throw new NotSupportedException();
                }
            }
            //not found
            return(null);
        }
示例#2
0
            /// <summary>
            /// read table if exists
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="tableName"></param>
            /// <param name="tables"></param>
            /// <param name="reader"></param>
            /// <param name="newTableDel"></param>
            /// <returns></returns>
            public T Read <T>(T resultTable) where T : TableEntry
            {
                if (_tables.TryGetTable(resultTable.Name, out TableEntry found))
                {
                    //found table name
                    //check if we have read this table or not
                    if (found is UnreadTableEntry unreadTableEntry)
                    {
                        //set header before actal read
                        resultTable.Header = found.Header;
                        if (unreadTableEntry.HasCustomContentReader)
                        {
                            resultTable = unreadTableEntry.CreateTableEntry(_input, resultTable);
                        }
                        else
                        {
                            resultTable.LoadDataFrom(_input);
                        }
                        //then replace
                        _tables.ReplaceTable(resultTable);
                        return(resultTable);
                    }
                    else
                    {
#if DEBUG
                        System.Diagnostics.Debug.WriteLine("this table is already loaded");
                        if (!(found is T))
                        {
                            throw new NotSupportedException();
                        }
#endif
                        return(found as T);
                    }
                }
                //not found
                return(null);
            }