本文整理汇总了C#中Sharpen.FilePath.ToURI方法的典型用法代码示例。如果您正苦于以下问题:C# FilePath.ToURI方法的具体用法?C# FilePath.ToURI怎么用?C# FilePath.ToURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sharpen.FilePath
的用法示例。
在下文中一共展示了FilePath.ToURI方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequireMain
/// <summary>
/// Calling this method establishes a module as being the main module of the
/// program to which this require() instance belongs.
/// </summary>
/// <remarks>
/// Calling this method establishes a module as being the main module of the
/// program to which this require() instance belongs. The module will be
/// loaded as if require()'d and its "module" property will be set as the
/// "main" property of this require() instance. You have to call this method
/// before the module has been loaded (that is, the call to this method must
/// be the first to require the module and thus trigger its loading). Note
/// that the main module will execute in its own scope and not in the global
/// scope. Since all other modules see the global scope, executing the main
/// module in the global scope would open it for tampering by other modules.
/// </remarks>
/// <param name="cx">the current context</param>
/// <param name="mainModuleId">the ID of the main module</param>
/// <returns>the "exports" property of the main module</returns>
/// <exception cref="System.InvalidOperationException">
/// if the main module is already loaded when
/// required, or if this require() instance already has a different main
/// module set.
/// </exception>
public virtual Scriptable RequireMain(Context cx, string mainModuleId)
{
if (this.mainModuleId != null)
{
if (!this.mainModuleId.Equals(mainModuleId))
{
throw new InvalidOperationException("Main module already set to " + this.mainModuleId);
}
return mainExports;
}
ModuleScript moduleScript;
try
{
// try to get the module script to see if it is on the module path
moduleScript = moduleScriptProvider.GetModuleScript(cx, mainModuleId, null, null, paths);
}
catch (Exception x)
{
throw;
}
catch (Exception x)
{
throw new Exception(x);
}
if (moduleScript != null)
{
mainExports = GetExportedModuleInterface(cx, mainModuleId, null, null, true);
}
else
{
if (!sandboxed)
{
Uri mainUri = null;
// try to resolve to an absolute URI or file path
try
{
mainUri = new Uri(mainModuleId);
}
catch (URISyntaxException)
{
}
// fall through
// if not an absolute uri resolve to a file path
if (mainUri == null || !mainUri.IsAbsoluteUri)
{
FilePath file = new FilePath(mainModuleId);
if (!file.IsFile())
{
throw ScriptRuntime.ThrowError(cx, nativeScope, "Module \"" + mainModuleId + "\" not found.");
}
mainUri = file.ToURI();
}
mainExports = GetExportedModuleInterface(cx, mainUri.ToString(), mainUri, null, true);
}
}
this.mainModuleId = mainModuleId;
return mainExports;
}