3.4 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-17T16:46:25.600912+00:00 | zai-org/GLM-5-FP8 | 1 | 95b12383e1ed5dba |
Documentation: EmbeddedResource
1. Purpose
EmbeddedResource is a static utility class that provides methods for loading embedded resources from .NET assemblies. It exists to abstract the complexity of locating and extracting manifest resources by name, supporting partial name matching. This class is part of the DatabaseInitializationScripts namespace, indicating its primary role is loading embedded database scripts (likely SQL files) that are packaged within the assembly at compile time.
2. Public Interface
public static StreamReader GetStream(System.Reflection.Assembly assembly, string name)
Signature: (Assembly, string) -> StreamReader
Locates an embedded resource within the specified assembly by performing a partial name match (using EndsWith). Returns a StreamReader wrapping the resource stream if found, or null if no matching resource name exists.
public static string GetString(System.Reflection.Assembly assembly, string name)
Signature: (Assembly, string) -> string
Retrieves the full text content of an embedded resource from the specified assembly. Internally calls GetStream, reads the entire content via ReadToEnd(), closes the stream, and returns the string.
public static string GetString(string name)
Signature: string -> string
Convenience overload that retrieves an embedded resource from the assembly containing the EmbeddedResource class itself (via typeof(EmbeddedResource).Assembly). Delegates to GetString(Assembly, string).
3. Invariants
- The class cannot be instantiated; the private constructor enforces static-only usage.
- Resource name matching is always a suffix match (
EndsWith), not an exact match. - The
GetStringmethods assume the resource exists; behavior is undefined (likelyNullReferenceException) if the resource is not found. - The
GetString(Assembly, string)method always closes theStreamReaderbefore returning.
4. Dependencies
This module depends on:
System.IO— forStreamReaderSystem.Reflection— forAssemblyand manifest resource APIs
What depends on this module:
- Not determinable from source alone. However, given the namespace
DatabaseInitializationScripts, consumers are likely database initialization logic that needs to load SQL scripts or configuration files embedded in the assembly.
5. Gotchas
-
Null return not handled in
GetString:GetStreamreturnsnullwhen no resource matches, butGetString(Assembly, string)immediately callssr.ReadToEnd()without null-checkingsr. This will throw aNullReferenceExceptionif the resource name is not found. -
Partial name matching ambiguity: The use of
EndsWith(name)means requesting"schema.sql"could match multiple resources (e.g.,"folderA.schema.sql"and"folderB.schema.sql"). The method returns the first match found, which depends onGetManifestResourceNames()ordering—this ordering is not guaranteed to be deterministic. -
No
using/dispose pattern:GetString(Assembly, string)usessr.Close()rather than ausingstatement. IfReadToEnd()throws an exception, the stream will not be closed. -
**Assembly coupling