This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
---
source_files:
- DataPRO/Modules/Database/DatabaseInitializationScripts/EmbeddedResource.cs
generated_at: "2026-04-17T16:46:25.600912+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "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 `GetString` methods assume the resource exists; behavior is undefined (likely `NullReferenceException`) if the resource is not found.
- The `GetString(Assembly, string)` method always closes the `StreamReader` before returning.
## 4. Dependencies
**This module depends on:**
- `System.IO` — for `StreamReader`
- `System.Reflection` — for `Assembly` and 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
1. **Null return not handled in `GetString`:** `GetStream` returns `null` when no resource matches, but `GetString(Assembly, string)` immediately calls `sr.ReadToEnd()` without null-checking `sr`. This will throw a `NullReferenceException` if the resource name is not found.
2. **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 on `GetManifestResourceNames()` ordering—this ordering is not guaranteed to be deterministic.
3. **No `using`/dispose pattern:** `GetString(Assembly, string)` uses `sr.Close()` rather than a `using` statement. If `ReadToEnd()` throws an exception, the stream will not be closed.
4. **Assembly coupling