/// <summary> /// Lazy init method to ensure the cache is built. /// </summary> public static void LazyInit() { if (wasInitialized) { return; } foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in asm.GetTypes()) { if (typeof(IPrototype).IsAssignableFrom(type) || type.GetCustomAttributes(true).Any((a) => a.GetType() == typeof(PrototypeDataSerializableAttribute))) { SerializableTypeCache cache = new SerializableTypeCache(); cache.Build(type); typeCache.Add(type, cache); } else if (!type.IsAbstract && !type.IsInterface && typeof(IPrototypeDataSerializer).IsAssignableFrom(type)) { serializers.Add(Activator.CreateInstance(type) as IPrototypeDataSerializer); } } } wasInitialized = true; }
/// <summary> /// Tries buildding the cache for the specified type. /// In case of an issue while building, null will be returned. /// /// If you want to know more as to why building failed, <see cref="GetBuildError(Type)"/> /// </summary> public static SerializableTypeCache TryBuild(Type type) { SerializableTypeCache stc = new SerializableTypeCache(); try { stc.Build(type); } catch (Exception ex) { buildErrors.Set(type, ex.ToString()); return(null); } return(stc); }