Skip to content

API Host FileSystemScriptSourceResolver

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

FileSystemScriptSourceResolver

以目录为根的默认文件系统脚本源码 Resolver。

Default file-system source resolver rooted at a directory.

命名空间:AuroraScript.Source。类型:class。

Namespace: AuroraScript.Source. Kind: class.

返回 .NET Host API 参考

Back to .NET Host API Reference

用途

Purpose

FileSystemScriptSourceResolver 是公开宿主类型。通过下方签名选择调用方式;对运行时对象、生命周期和异常,应由宿主在边界处明确处理。

Default file-system source resolver rooted at a directory.

注意

依赖解析从 importer 的 FullPath 出发;相对路径指向且文件存在时,目标可能位于 Root 外。

Dependency resolution follows importer.FullPath and may resolve outside Root if the relative path points there and the file exists.

注意

此 Resolver 返回的引用仍将自身 Root 作为 BaseDirectory,以便 GetSourceAsync 路由回它。

References returned by this resolver still use this resolver Root as BaseDirectory so GetSourceAsync routes back here.

简单示例

Simple Example

下面是 FileSystemScriptSourceResolver 的最小使用方式。

A minimal use of FileSystemScriptSourceResolver.

var resolver = ScriptSources.FileSystem("./scripts");

var options = EngineOptions.Default.WithCompiler(builder =>
    builder.SourceResolver = resolver);

成员

Members

FileSystemScriptSourceResolver(string root = null, Encoding encoding = null)

创建 FileSystemScriptSourceResolver 实例。

Use the member according to its public signature.

Parameters:

  • root
    解析器或来源的根路径。

    Root path for a resolver or source.

  • encoding
    读写文本使用的编码。

    Encoding used to read or write text.

Returns

新建的 FileSystemScriptSourceResolver 实例。

A new FileSystemScriptSourceResolver instance.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

var value = new FileSystemScriptSourceResolver(/* 参数 */);

string Root

读取 Root 属性。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 string

Returns string.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

FileSystemScriptSourceResolver value = /* 从宿主 API 获取实例 */;
var current = value.Root;

ValueTask<ScriptSourceReference?> ResolveAsync(ScriptSourceReference? importer, string requestedPath, ScriptResolveContext context, CancellationToken cancellationToken = default)

调用 ResolveAsync 完成其公开操作。

Resolves an entry from Root or a dependency from the importing file path.

Parameters:

  • importer
    发起依赖解析的来源。

    Source initiating dependency resolution.

  • requestedPath
    导入或包含请求的原始路径。

    Raw path requested by import or include.

  • context
    当前脚本执行上下文。

    Current script execution context.

  • cancellationToken
    取消异步操作的令牌。

    Token that cancels the asynchronous operation.

Returns

返回 ValueTask<ScriptSourceReference?>

Returns ValueTask<ScriptSourceReference?>.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

FileSystemScriptSourceResolver value = /* 从宿主 API 获取实例 */;
var result = value.ResolveAsync(/* importer */, /* requestedPath */, /* context */, /* cancellationToken */);

ValueTask<ScriptSource> GetSourceAsync(ScriptSourceReference reference, CancellationToken cancellationToken = default)

调用 GetSourceAsync 完成其公开操作。

Use the member according to its public signature.

Parameters:

  • reference
    已解析来源的稳定引用。

    Stable reference to a resolved source.

  • cancellationToken
    取消异步操作的令牌。

    Token that cancels the asynchronous operation.

Returns

返回 ValueTask<ScriptSource>

Returns ValueTask<ScriptSource>.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

FileSystemScriptSourceResolver value = /* 从宿主 API 获取实例 */;
var result = value.GetSourceAsync(/* reference */, /* cancellationToken */);

IAsyncEnumerable<ScriptSource> GetAllSourcesAsync(ScriptSourceQuery query, CancellationToken cancellationToken = default)

调用 GetAllSourcesAsync 完成其公开操作。

Enumerates script files under Root for BuildAsync().

Parameters:

  • query
    用于筛选来源的查询。

    Query used to filter sources.

  • cancellationToken
    取消异步操作的令牌。

    Token that cancels the asynchronous operation.

Returns

返回 IAsyncEnumerable<ScriptSource>

Returns IAsyncEnumerable<ScriptSource>.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

FileSystemScriptSourceResolver value = /* 从宿主 API 获取实例 */;
var result = value.GetAllSourcesAsync(/* query */, /* cancellationToken */);

Clone this wiki locally