当前位置: 首页>>代码示例>>C#>>正文


C# FilePath.ToURI方法代码示例

本文整理汇总了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;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:81,代码来源:Require.cs


注:本文中的Sharpen.FilePath.ToURI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。