本文整理汇总了C#中IronPython.Runtime.PythonModule.GetName方法的典型用法代码示例。如果您正苦于以下问题:C# PythonModule.GetName方法的具体用法?C# PythonModule.GetName怎么用?C# PythonModule.GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronPython.Runtime.PythonModule
的用法示例。
在下文中一共展示了PythonModule.GetName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportNestedModule
private static object ImportNestedModule(CodeContext/*!*/ context, PythonModule/*!*/ module, string name, List/*!*/ path) {
object ret;
string fullName = CreateFullName(module.GetName() as string, name);
if (TryGetExistingOrMetaPathModule(context, fullName, path, out ret)) {
module.__dict__[name] = ret;
return ret;
}
if (TryGetNestedModule(context, module, name, out ret)) {
return ret;
}
ImportFromPath(context, name, fullName, path);
object importedModule;
if (PythonContext.GetContext(context).SystemStateModules.TryGetValue(fullName, out importedModule)) {
module.__dict__[name] = importedModule;
return importedModule;
}
throw PythonOps.ImportError("cannot import {0} from {1}", name, module.GetName());
}
示例2: ReloadBuiltinModule
private static void ReloadBuiltinModule(CodeContext/*!*/ context, PythonModule/*!*/ module) {
Assert.NotNull(module);
Debug.Assert(module.GetName() is string, "Module is reloadable only if its name is a non-null string");
Type type;
string name = (string)module.GetName();
PythonContext pc = PythonContext.GetContext(context);
if (!pc.BuiltinModules.TryGetValue(name, out type)) {
throw PythonOps.ImportError("no module named {0}", module.GetName());
}
// should be a built-in module which we can reload.
Debug.Assert(((PythonDictionary)module.__dict__)._storage is ModuleDictionaryStorage);
((ModuleDictionaryStorage)module.__dict__._storage).Reload();
}
示例3: ReloadBuiltinModule
private static void ReloadBuiltinModule(CodeContext/*!*/ context, PythonModule/*!*/ module) {
Assert.NotNull(module);
Debug.Assert(module.GetName() is string, "Module is reloadable only if its name is a non-null string");
Type type;
string name = (string)module.GetName();
PythonContext pc = PythonContext.GetContext(context);
if (!pc.Builtins.TryGetValue(name, out type)) {
throw new NotImplementedException();
}
// should be a built-in module which we can reload.
Debug.Assert(module.Scope.Dict is PythonDictionary);
Debug.Assert(((PythonDictionary)module.Scope.Dict)._storage is ModuleDictionaryStorage);
((ModuleDictionaryStorage)((PythonDictionary)module.Scope.Dict)._storage).Reload();
}
示例4: ReloadModule
internal static object ReloadModule(CodeContext/*!*/ context, PythonModule/*!*/ module, PythonFile file) {
PythonContext pc = PythonContext.GetContext(context);
// We created the module and it only contains Python code. If the user changes
// __file__ we'll reload from that file.
string fileName = module.GetFile() as string;
// built-in module:
if (fileName == null) {
ReloadBuiltinModule(context, module);
return module;
}
string name = module.GetName() as string;
if (name != null) {
List path = null;
// find the parent module and get it's __path__ property
int dotIndex = name.LastIndexOf('.');
if (dotIndex != -1) {
PythonModule parentModule;
path = GetParentPathAndModule(context, name.Substring(0, dotIndex), out parentModule);
}
object reloaded;
if (TryLoadMetaPathModule(context, module.GetName() as string, path, out reloaded) && reloaded != null) {
return module;
}
List sysPath;
if (PythonContext.GetContext(context).TryGetSystemPath(out sysPath)) {
object ret = ImportFromPathHook(context, name, name, sysPath, null);
if (ret != null) {
return ret;
}
}
}
SourceUnit sourceUnit;
if (file != null) {
sourceUnit = pc.CreateSourceUnit(new PythonFileStreamContentProvider(file), fileName, file.Encoding, SourceCodeKind.File);
} else {
if (!pc.DomainManager.Platform.FileExists(fileName)) {
throw PythonOps.SystemError("module source file not found");
}
sourceUnit = pc.CreateFileUnit(fileName, pc.DefaultEncoding, SourceCodeKind.File);
}
pc.GetScriptCode(sourceUnit, name, ModuleOptions.None).Run(module.Scope);
return module;
}
示例5: ImportNestedModule
private static object ImportNestedModule(CodeContext/*!*/ context, PythonModule/*!*/ module, string name, List/*!*/ path) {
object ret;
//NewPythonModule module = PythonContext.GetContext(context).EnsurePythonModule(scope);
string fullName = CreateFullName(module.GetName() as string, name);
if (TryGetExistingOrMetaPathModule(context, fullName, path, out ret)) {
module.Scope.SetVariable(SymbolTable.StringToId(name), ret);
return ret;
}
if (TryGetNestedModule(context, module, name, out ret)) {
return ret;
}
ImportFromPath(context, name, fullName, path);
object importedModule;
if (PythonContext.GetContext(context).SystemStateModules.TryGetValue(fullName, out importedModule)) {
module.Scope.SetVariable(SymbolTable.StringToId(name), importedModule);
return importedModule;
}
throw PythonOps.ImportError("cannot import {0} from {1}", name, module.GetName());
}