// dnlib: See LICENSE.txt for more info
using System;
using System.Diagnostics;
using dnlib.DotNet.MD;
namespace dnlib.DotNet {
///
/// A high-level representation of a row in the ClassLayout table
///
public abstract class ClassLayout : IMDTokenProvider {
///
/// The row id in its table
///
protected uint rid;
///
public MDToken MDToken => new MDToken(Table.ClassLayout, rid);
///
public uint Rid {
get => rid;
set => rid = value;
}
///
/// From column ClassLayout.PackingSize
///
public ushort PackingSize {
get => packingSize;
set => packingSize = value;
}
///
protected ushort packingSize;
///
/// From column ClassLayout.ClassSize
///
public uint ClassSize {
get => classSize;
set => classSize = value;
}
///
protected uint classSize;
}
///
/// A ClassLayout row created by the user and not present in the original .NET file
///
public class ClassLayoutUser : ClassLayout {
///
/// Default constructor
///
public ClassLayoutUser() {
}
///
/// Constructor
///
/// PackingSize
/// ClassSize
public ClassLayoutUser(ushort packingSize, uint classSize) {
this.packingSize = packingSize;
this.classSize = classSize;
}
}
///
/// Created from a row in the ClassLayout table
///
sealed class ClassLayoutMD : ClassLayout, IMDTokenProviderMD {
readonly uint origRid;
///
public uint OrigRid => origRid;
///
/// Constructor
///
/// The module which contains this ClassLayout row
/// Row ID
/// If is null
/// If is invalid
public ClassLayoutMD(ModuleDefMD readerModule, uint rid) {
#if DEBUG
if (readerModule is null)
throw new ArgumentNullException("readerModule");
if (readerModule.TablesStream.ClassLayoutTable.IsInvalidRID(rid))
throw new BadImageFormatException($"ClassLayout rid {rid} does not exist");
#endif
origRid = rid;
this.rid = rid;
bool b = readerModule.TablesStream.TryReadClassLayoutRow(origRid, out var row);
Debug.Assert(b);
classSize = row.ClassSize;
packingSize = row.PackingSize;
}
}
}