Stabilize initialization of XmlPropertyTokens

This commit is contained in:
CloneTrooper1019 2020-07-31 10:14:48 -05:00
parent 77dff70e4b
commit 0a6c8f38d4
2 changed files with 9 additions and 5 deletions

Binary file not shown.

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
@ -14,13 +15,16 @@ namespace RobloxFiles.XmlFormat
{ {
// Initialize the PropertyToken handler singletons. // Initialize the PropertyToken handler singletons.
Type IXmlPropertyToken = typeof(IXmlPropertyToken); Type IXmlPropertyToken = typeof(IXmlPropertyToken);
var assembly = Assembly.GetExecutingAssembly();
var handlerTypes = AppDomain.CurrentDomain.GetAssemblies() var handlerTypes = assembly.GetTypes()
.SelectMany(assembly => assembly.GetTypes()) .Where(type => IXmlPropertyToken.IsAssignableFrom(type))
.Where(type => type != IXmlPropertyToken) .Where(type => type != IXmlPropertyToken);
.Where(type => IXmlPropertyToken.IsAssignableFrom(type));
var propTokens = handlerTypes
.Select(handlerType => Activator.CreateInstance(handlerType))
.Cast<IXmlPropertyToken>();
var propTokens = handlerTypes.Select(handlerType => Activator.CreateInstance(handlerType) as IXmlPropertyToken);
var tokenHandlers = new Dictionary<string, IXmlPropertyToken>(); var tokenHandlers = new Dictionary<string, IXmlPropertyToken>();
foreach (IXmlPropertyToken propToken in propTokens) foreach (IXmlPropertyToken propToken in propTokens)