/// <summary> /// Creates a type with a given name /// </summary> /// <param name="type">Python object</param> /// <returns>Type object</returns> private Type CreateType(PyObject type) { PythonActivator pythonType; if (!_pythonActivators.TryGetValue(type.Handle, out pythonType)) { AssemblyName an; using (Py.GIL()) { an = new AssemblyName(type.Repr().Split('\'')[1]); } var typeBuilder = AppDomain.CurrentDomain .DefineDynamicAssembly(an, AssemblyBuilderAccess.Run) .DefineDynamicModule("MainModule") .DefineType(an.Name, TypeAttributes.Class, typeof(DynamicData)); pythonType = new PythonActivator(typeBuilder.CreateType(), type); ObjectActivator.AddActivator(pythonType.Type, pythonType.Factory); // Save to prevent future additions _pythonActivators.Add(type.Handle, pythonType); } return(pythonType.Type); }