/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
// from dnlib
using System.Collections.ObjectModel;
namespace dnSpy.Contracts.Hex.Files.DotNet {
///
/// A MD table (eg. Method table)
///
public sealed class MDTable {
///
/// Gets the span
///
public HexSpan Span { get; }
///
/// Gets the table
///
public Table Table { get; }
///
/// Gets the name of this table
///
public string Name => TableInfo.Name;
///
/// Returns total number of rows
///
public uint Rows { get; }
///
/// Gets the total size in bytes of one row in this table
///
public uint RowSize => (uint)TableInfo.RowSize;
///
/// Returns all the columns
///
public ReadOnlyCollection Columns => TableInfo.Columns;
///
/// Returns true if there are no valid rows
///
public bool IsEmpty => Rows == 0;
///
/// Returns info about this table
///
public TableInfo TableInfo { get; }
///
/// Constructor
///
/// Start position
/// The table
/// Number of rows in this table
/// Info about this table
public MDTable(HexPosition position, Table table, uint rows, TableInfo tableInfo) {
Table = table;
Rows = rows;
TableInfo = tableInfo;
Span = new HexSpan(position, (ulong)rows * (uint)tableInfo.RowSize);
}
///
/// Checks whether the row exists
///
/// Row ID
public bool IsValidRID(uint rid) => rid != 0 && rid <= Rows;
///
/// Checks whether the row does not exist
///
/// Row ID
public bool IsInvalidRID(uint rid) => rid == 0 || rid > Rows;
}
}