public static void Init() { if (_isInit) { return; } lock (_padLock) { if (_isInit) { return; } try { //IsInitialized = true; Dictionary <string, JsonConverter> dict = _convertersCache; var convs = ChoType.GetAllTypes().Where(t => typeof(JsonConverter).IsAssignableFrom(t) && !t.IsGenericType && ChoType.HasDefaultConstructor(t)) .Distinct().ToArray(); foreach (var c in convs) { var dad = ChoTypeDescriptor.GetTypeAttribute <ChoDisableAutoDiscoverabilityAttribute>(c); if (dad != null && dad.Flag) { continue; } if (dict.ContainsKey(c.Name)) { continue; } try { dict.Add(c.Name, Activator.CreateInstance(c) as JsonConverter); var dna = ChoTypeDescriptor.GetTypeAttribute <DisplayNameAttribute>(c); if (dna != null && !dna.DisplayName.IsNullOrWhiteSpace()) { if (!dict.ContainsKey(dna.DisplayName)) { dict.Add(dna.DisplayName, Activator.CreateInstance(c) as JsonConverter); } } } catch { } } } catch { } _isInit = true; } }
public void ScanAndLoad() { var types = ChoType.GetAllTypes().Where(t => typeof(IComparer).IsAssignableFrom(t)).ToArray(); foreach (Type compType in types) { try { var comp = ChoActivator.CreateInstance(compType) as IComparer; if (comp != null) { if (compType.IsGenericType) { Type type = comp.GetType().GetGenericArguments()[0]; Add(type, comp); } else { Type objType = compType.GetAllInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IComparer <>)) .Select(i => i.GetGenericArguments()[0]).FirstOrDefault(); if (objType != null) { Add(objType, comp); } else { var attr = compType.GetCustomAttribute <ChoComparerObjectTypeAttribute>(); if (attr != null && attr.Type != null) { Add(attr.Type, comp); } } } } } catch { } } }