private void InitializeClasses() { var list = new List <Tuple <int, Type> >(); var attributeType = typeof(InitializeValueConverterAttribute); // check all loaded assemblies var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { if (!BindingUtility.IsScriptAssembly(assembly)) { // only handle script assembly continue; } // get all types Type[] types = null; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException) { // ignore types that cannot be loaded continue; } // iterate all types foreach (var type in types) { if (!type.IsDefined(attributeType, false)) { continue; } // get attribute var attribute = BindingUtility.GetAttribute <InitializeValueConverterAttribute>(type, false); // add it list.Add(Tuple.Create(attribute.Order, type)); } } // sort based on order list.Sort((lhs, rhs) => lhs.Item1.CompareTo(rhs.Item1)); foreach (var item in list) { var type = item.Item2; // run class constructor System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle); } }