void TryAddDefaultBlock(IUTLFileBlockHandler h) { if (GetFirstBlock(h.BlockTypeID) == null) { FileBlocks.Add(h); } }
public void Read(System.IO.StreamReader inf) { FileBlocks.Clear(); while (!inf.EndOfStream) { //Read blocks string blocktype = inf.ReadLine(); int blocklen = int.Parse(inf.ReadLine(), System.Globalization.CultureInfo.InvariantCulture); if (BlockHandlerTypes.ContainsKey(blocktype)) { //Known blocktype, create and add IUTLFileBlockHandler h = (IUTLFileBlockHandler)BlockHandlerTypes[blocktype].GetConstructor(new Type[] { }).Invoke(null); h.Read(inf, blocklen); FileBlocks.Add(h); } else { //Unknown blocktype, skip ahead char[] qq = new char[blocklen]; inf.Read(qq, 0, blocklen); } } CreateDefaultBlocks(); }
static void AddHandlerType(Type t) { if (!typeof(IUTLFileBlockHandler).IsAssignableFrom(t)) { throw new Exception("UTLFileExtraBlockManager: Cannot add handler type."); } //Create one to determine its typeid IUTLFileBlockHandler h = (IUTLFileBlockHandler)t.GetConstructor(new Type[] { }).Invoke(null); string tid = h.BlockTypeID; if (BlockHandlerTypes.ContainsKey(tid)) { throw new Exception("UTLFileExtraBlockManager: duplicate handler id (" + tid + ")"); } BlockHandlerTypes[tid] = t; }
void TryAddDefaultBlock(IUTLFileBlockHandler h) { if (GetFirstBlock(h.BlockTypeID) == null) FileBlocks.Add(h); }