ToURI() public méthode

public ToURI ( ) : Uri
Résultat System.Uri
 public static Uri FromFile(this FilePath file)
 {
     return(file.ToURI());
 }
Exemple #2
0
		/// <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;
		}