Beispiel #1
0
        public LiftedList <TChild> LoadIndirectChildren <TChild, TParentField>(
            TParentField parent,
            MetadataTable childTable,
            UnsafeSelector <TParentField> parentSelector,
            CreateObjectDelegate <TChild> factory
            ) where TChild : class
        {
            CheckDisposed();
            //It is valid for the child table to not be sorted, but I don't expect such a case to occur in practice.
            //I imagine that this could maybe happen with ENC, but we don't need to be able to decompile enc assemblies.
            //In either case, if we do end up needing to support assemblies with unsorted meta-data tables, then we should probably
            //add our best attempt at an efficent fallback in that case. For now we just throw.
            IsSorted(childTable).Assume("The generic param constraint table is not sorted.");

            var glb = GreatestLowerBound(
                childTable,
                parent,
                parentSelector
                );
            var lub = LeastUpperBound(
                childTable,
                parent,
                parentSelector
                );

            var ret = new LiftedList <TChild>(
                (glb - lub - 1).Value,
                index => GetRow(index.ToZB() + lub + 1, childTable),
                factory,
                () => IsDisposed
                );

            return(ret);
        }
Beispiel #2
0
        //# Returns the index of the smallest item in [table] strictly greater than (>) [value]. If no such element
        //# exists then the index immedietly beyond the end of the table (count + 1) is returned.
        //#
        //# Parameters
        //# ============
        //# [table] : The metadata table to search.
        //# [value] : The value to search for.
        //# [selector]
        //#     A function that projects the desired sort field(s) from the rows of the table. The table must be sorted
        //#     by selector.
        public ZeroBasedIndex LeastUpperBound <T>(MetadataTable table, T value, UnsafeSelector <T> selector)
        {
            CheckDisposed();
            table.CheckDefined("table");
            selector.CheckNotNull("selector");

            if (!IsSorted(table))
            {
                throw new InvalidOperationException(string.Format("The table '{0}' is not sorted", table));
            }

            return(new TableWrapper(table, this).LeastUpperBound(
                       x => selector((void *)x),
                       value,
                       Comparer <T> .Default
                       ).ToZB());
        }
Beispiel #3
0
        IReadOnlyList <T> LoadDirectChildrenFromMap <T>(
            MetadataTable mapTable,
            MetadataTable childTable,
            UnsafeSelector <OneBasedIndex> parentSelector,
            GetTokenDelegate tokenSelector,
            CreateObjectDelegate <T> factory
            ) where T : class
        {
            //It is valid for the map table to not be sorted. However, I don't expect this to happen in
            //practice, so for now we throw an exception in that case. If we do end up needing to support
            //assemblies with unsorted meta-data tables then we will need to add some sort of fallback
            //here.
            mapTable.IsSorted(Module.PEFile).Assume("The table is not sorted");

            var mapIndex = mapTable.Find(
                (OneBasedIndex)MetadataTable.TypeDef.RowIndex(m_pRow, Module.PEFile),
                parentSelector,
                Module.PEFile
                );

            IReadOnlyList <T> ret;

            if (mapIndex < 0)
            {
                ret = new List <T>(0).AsReadOnly();
            }
            else
            {
                ret = Module.PEFile.LoadDirectChildren(
                    childTable,
                    tokenSelector,
                    factory,
                    mapTable,
                    mapTable.GetRow(mapIndex, Module.PEFile)
                    );
            }
            return(ret);
        }
Beispiel #4
0
 public ZeroBasedIndex Find <T>(MetadataTable table, T value, UnsafeSelector <T> selector)
 {
     CheckDisposed();
     //TODO Implement this
     throw new NotImplementedException();
 }
Beispiel #5
0
 public unsafe static ZeroBasedIndex Find <T>(this MetadataTable table, T value, UnsafeSelector <T> selector, PEFile peFile)
 {
     return(peFile.CheckNotNull("peFile").Find(table, value, selector));
 }