// dnlib: See LICENSE.txt for more info
using System;
using System.Collections.Generic;
namespace dnlib.DotNet.Writer {
///
/// Contains a list of s
///
public class ChunkList : ChunkListBase where T : class, IChunk {
///
/// Default constructor
///
public ChunkList() => chunks = new List();
///
/// Add a
///
/// The chunk to add or null if none
/// Chunk alignment
public void Add(T chunk, uint alignment) {
if (setOffsetCalled)
throw new InvalidOperationException("SetOffset() has already been called");
if (chunk is not null)
chunks.Add(new Elem(chunk, alignment));
}
///
/// Remove a
///
/// The chunk to remove or null if none
/// Alignment of the chunk, or null if the chunk cannot be removed.
public uint? Remove(T chunk) {
if (setOffsetCalled)
throw new InvalidOperationException("SetOffset() has already been called");
if (chunk is not null) {
var chunks = this.chunks;
for (int i = 0; i < chunks.Count; i++) {
if (chunks[i].chunk == chunk) {
uint alignment = chunks[i].alignment;
chunks.RemoveAt(i);
return alignment;
}
}
}
return null;
}
}
}