private void load_global_sub(string module, string name) { IObjectConstructor constructor; string key = module + "." + name; if (objectConstructors.ContainsKey(key)) { constructor = objectConstructors[module + "." + name]; } else { switch (module) { // check if it is an exception case "exceptions": // python 2.x constructor = new ExceptionConstructor(typeof(PythonException), module, name); break; case "builtins": case "__builtin__": if (name.EndsWith("Error") || name.EndsWith("Warning") || name.EndsWith("Exception") || name == "GeneratorExit" || name == "KeyboardInterrupt" || name == "StopIteration" || name == "SystemExit") { // it's a python 3.x exception constructor = new ExceptionConstructor(typeof(PythonException), module, name); } else { // return a dictionary with the class's properties constructor = new ClassDictConstructor(module, name); } break; default: constructor = new ClassDictConstructor(module, name); break; } } stack.add(constructor); }
private static ExceptionConstructor ExceptionScanner(string assemblyMarker, string nameSpace, string assertionExceptionName, string ignoreExceptionName, string inconclusiveExceptionName) { int foundExceptions = 0; var result = new ExceptionConstructor(); var defaultSignature = new[] { typeof(string) }; foreach ( var assembly in AppDomain.CurrentDomain.GetAssemblies() .Where(ass => ass.FullName.ToLowerInvariant().Contains(assemblyMarker))) { foreach (var type in assembly.GetExportedTypes()) { if (type.Namespace.StartsWith(nameSpace)) { if (type.Name == assertionExceptionName) { var info = type.GetConstructor(defaultSignature); if (info != null) { result.FailedException = info; } foundExceptions++; } else if (type.Name == ignoreExceptionName) { var info = type.GetConstructor(defaultSignature); if (info != null) { result.IgnoreException = info; } foundExceptions++; } else if (type.Name == inconclusiveExceptionName) { var info = type.GetConstructor(defaultSignature); if (info != null) { // if we do not expect a ignore exception, we remap inconclusive result.InconclusiveException = info; foundExceptions++; if (string.IsNullOrEmpty(ignoreExceptionName)) { result.IgnoreException = info; foundExceptions++; } } } } // stop search if we found everything if (foundExceptions == 3) { return result; } } } return null; }