public GlyphFactoryInfo(int order, HexGlyphFactory factory, HexGlyphFactoryProvider glyphFactoryProvider) { Order = order; Factory = factory ?? throw new ArgumentNullException(nameof(factory)); FactoryProvider = glyphFactoryProvider ?? throw new ArgumentNullException(nameof(glyphFactoryProvider)); Canvas = new Canvas { Background = Brushes.Transparent }; }
void InitializeGlyphFactories() { var oldFactories = new Dictionary <HexGlyphFactoryProvider, HexGlyphFactory>(); foreach (var info in glyphFactories.Values) { oldFactories[info.FactoryProvider] = info.Factory; } glyphFactories.Clear(); bool newFactory = false; int order = 0; foreach (var lazy in lazyGlyphFactoryProviders) { HexGlyphFactory glyphFactory = null; foreach (var type in lazy.Metadata.TagTypes) { Debug.Assert(type != null); if (type == null) { break; } Debug.Assert(!glyphFactories.ContainsKey(type)); if (glyphFactories.ContainsKey(type)) { continue; } Debug.Assert(typeof(HexGlyphTag).IsAssignableFrom(type)); if (!typeof(HexGlyphTag).IsAssignableFrom(type)) { continue; } if (glyphFactory == null) { if (oldFactories.TryGetValue(lazy.Value, out glyphFactory)) { oldFactories.Remove(lazy.Value); } else { glyphFactory = lazy.Value.GetGlyphFactory(wpfHexViewHost.HexView, this); if (glyphFactory == null) { break; } newFactory = true; } } glyphFactories.Add(type, new GlyphFactoryInfo(order++, glyphFactory, lazy.Value)); } } foreach (var factory in oldFactories.Values) { (factory as IDisposable)?.Dispose(); } if (newFactory || oldFactories.Count != 0) { childCanvases = glyphFactories.Values.OrderBy(a => a.Order).Select(a => a.Canvas).ToArray(); iconCanvas.Children.Clear(); foreach (var c in childCanvases) { iconCanvas.Children.Add(c); } RefreshEverything(); } }