using System; using System.Collections.Generic; namespace NBTExplorer.Model { public delegate bool NamePatternTestFunc (string path); public delegate DataNode NodeCreateFunc (string path); public class FileTypeRecord { public NamePatternTestFunc NamePatternTest { get; set; } public NodeCreateFunc NodeCreate { get; set; } } public class FileTypeRegistry { private static Dictionary _registry = new Dictionary(); public static FileTypeRecord Lookup (Type type) { if (_registry.ContainsKey(type)) return _registry[type]; else return null; } public static void Register (Type type, FileTypeRecord record) { _registry[type] = record; } public static void Register (FileTypeRecord record) { Register(typeof(T), record); } public static IEnumerable> RegisteredTypes { get { foreach (var item in _registry) yield return item; } } static FileTypeRegistry () { try { Register(new FileTypeRecord() { NamePatternTest = NbtFileDataNode.SupportedNamePattern, NodeCreate = NbtFileDataNode.TryCreateFrom, }); Register(new FileTypeRecord() { NamePatternTest = RegionFileDataNode.SupportedNamePattern, NodeCreate = RegionFileDataNode.TryCreateFrom, }); Register(new FileTypeRecord() { NamePatternTest = CubicRegionDataNode.SupportedNamePattern, NodeCreate = CubicRegionDataNode.TryCreateFrom, }); } catch (Exception e) { //Program.StaticInitFailure(e); } } } }