// Public Methods public void Add(Type t, NodeTranslatorBound b) { List <NodeTranslatorBound> x; if (!_items.TryGetValue(t, out x)) { _items[t] = x = new List <NodeTranslatorBound>(); } x.Add(b); }
/// <summary> /// Porządkuje dane i przygotowuje cache do tłumaczeń /// </summary> public void Prepare() { var allTypes = (from assembly in TranslationAssemblies from type in assembly.GetTypes() select type).ToArray(); foreach (var type in allTypes) { if (type.IsInterface || type.IsAbstract) { continue; } var interfaces = type.GetInterfaces(); foreach (var interfaceType in interfaces) { var generic = interfaceType.IsGenericType ? interfaceType.GetGenericTypeDefinition() : interfaceType; #region IPyNodeTranslator if (generic == typeof(IPyNodeTranslator <>)) { var genericType = interfaceType.GetGenericArguments()[0]; var obj = Activator.CreateInstance(type); var map = type.GetInterfaceMap(interfaceType); var methods = map.InterfaceMethods; var methodTranslateToPy = methods.Single(ii => ii.Name == nameof(IPyNodeTranslator <IValue> .TranslateToPython)); var gpmethod = methods.Single(ii => ii.Name == nameof(IPyNodeTranslator <IValue> .GetPriority)); var bound = new NodeTranslatorBound(methodTranslateToPy, obj, gpmethod); NodeTranslators.Add(genericType, bound); } #endregion #region IModuleProcessor // ReSharper disable once InvertIf if (generic == typeof(IModuleProcessor)) { var obj = Activator.CreateInstance(type) as IModuleProcessor; ModuleProcessors.Add(obj); } #endregion } } }
private static int?GetNodeTranslatorBoundPriority(NodeTranslatorBound i) { // use this named method insead of lambda for performace reasons return(i.Priority); }