Skip to content

API Host ScriptSource

Liu.Yandong.Hanks edited this page Aug 19, 2026 · 3 revisions

脚本源码与引用

ScriptSource and References

.NET Host API 目录

.NET Host API Directory

概述

Overview

ScriptSource 表示源码文本及其路径身份;MemorySource 是字符串后备实现;ScriptSourceReference 是 Resolver 解析后可稳定路由的身份。它们通常由 Resolver 创建,应用代码通常使用 ScriptSources

ScriptSource represents source text and path identity; MemorySource is a string-backed implementation; ScriptSourceReference is the stable identity produced by resolution. Resolvers usually create these types, while application code usually uses ScriptSources.

ScriptSource.BaseDirectory / SourcePath / FullPath / Code

Returns

分别为 Resolver 根、模块相对路径、完整或虚拟路径、源码文本。

Resolver root, module-relative path, full or virtual path, and source text.

ScriptSource source = new MemorySource("mem://app/", "mem://app/main.as", "@module(MAIN);");
Console.WriteLine(source.FullPath);
Console.WriteLine(source.Code);

ScriptSource.ReadSource()

Parameters:

  • 无。

    None.

Returns

源码文本。

Source text.

var source = new MemorySource("mem://app/", "mem://app/main.as", "@module(MAIN);");
var text = source.ReadSource();

MemorySource(baseDirectory, fullPath, text)

Parameters:

  • baseDirectory
    Resolver 根。

    Resolver root.

  • fullPath
    虚拟完整路径。

    Virtual full path.

  • text
    源码。

    Source text.

Returns

内存源码。

In-memory source.

var source = new MemorySource("mem://app/", "mem://app/main.as", "@module(MAIN);");

ScriptSourceReference(baseDirectory, fullPath[, modulePath])

Parameters:

  • baseDirectory
    应读取此引用的 Resolver 根。

    Resolver root that reads this reference.

  • fullPath
    规范化完整路径。

    Normalized full path.

  • modulePath
    可选模块相对路径。

    Optional module-relative path.

Returns

值类型引用。

Value-type reference.

var reference = new ScriptSourceReference("mem://app/", "mem://app/main.as", "main.as");
Console.WriteLine(reference.ModulePath);

Clone this wiki locally