AnkiIO 1.0.2
Build, validate, import, and export Anki-compatible decks from .NET
Loading...
Searching...
No Matches
AnkiIO.AnkiValidator Class Reference

Checks a complete deck hierarchy before native JSON, CrowdAnki-style JSON, or APKG output. More...

Static Public Member Functions

static AnkiValidationResult Validate (AnkiDeck root)
 Validates a root deck and every reachable descendant without modifying them.
static AnkiValidationResult Validate (IEnumerable< AnkiDeck > roots)
 Validates several top-level deck hierarchies as one output graph.

Detailed Description

Checks a complete deck hierarchy before native JSON, CrowdAnki-style JSON, or APKG output.

Validation is read-only and returns every detected content error instead of failing at the first one. Checks cover duplicate object IDs, conflicting note-type definitions, missing fields or templates, template field references, scheduler type/queue combinations, non-negative review counters, new-card counters, and the three-bit card flag.

Active scheduling pairs are New/New, Learning/Learning, Learning/DayLearning, Review/Review, Relearning/Learning, and Relearning/DayLearning. Suspended, sibling-buried, scheduler-buried, and preview queues retain any defined underlying card type. Validation preserves queue-specific values; it does not run Anki's scheduler or infer a new due date.

The hierarchy is mutable and not thread-safe, so callers must not change it while validation enumerates it.

Definition at line 18 of file AnkiValidator.cs.

Member Function Documentation

◆ Validate() [1/2]

AnkiValidationResult AnkiIO.AnkiValidator.Validate ( AnkiDeck root)
inlinestatic

Validates a root deck and every reachable descendant without modifying them.

Parameters
rootThe root of the hierarchy to inspect.
Returns
An immutable diagnostic snapshot and aggregate validity decision.
Exceptions
ArgumentNullExceptionroot is null.
if (!result.IsValid)
{
foreach (AnkiDiagnostic error in result.Diagnostics.Where(d => d.Severity == AnkiDiagnosticSeverity.Error))
{
Console.Error.WriteLine($"{error.Code}: {error.Message}");
}
}
Provides one machine-readable validation, compatibility, or preservation finding.
Captures the ordered diagnostics and write/no-write decision from one validation pass.
bool IsValid
Gets whether validated serialization and package creation may proceed.
IReadOnlyList< AnkiDiagnostic > Diagnostics
Gets findings in deterministic hierarchy and card traversal order.
Checks a complete deck hierarchy before native JSON, CrowdAnki-style JSON, or APKG output.
static AnkiValidationResult Validate(AnkiDeck root)
Validates a root deck and every reachable descendant without modifying them.
AnkiDiagnosticSeverity
Classifies whether a diagnostic is explanatory, lossy, or blocks a validated write.

Definition at line 36 of file AnkiValidator.cs.

◆ Validate() [2/2]

AnkiValidationResult AnkiIO.AnkiValidator.Validate ( IEnumerable< AnkiDeck > roots)
inlinestatic

Validates several top-level deck hierarchies as one output graph.

Parameters
rootsThe non-empty sequence of hierarchy roots to inspect. The sequence is enumerated once into a snapshot before validation starts; individual deck graphs remain live and must not be mutated concurrently.
Returns
An immutable diagnostic snapshot whose uniqueness checks are shared across every supplied hierarchy.

Use this overload before producing a package that contains more than one root. Calling Validate(AnkiDeck) separately for each root cannot detect an ID reused by two different hierarchies or two conflicting note-type definitions with the same ID. Package writers use this overload automatically.

This validates deck-domain structure and scheduler state. It does not inspect ZIP safety, media payload availability, or same-name media collisions; those checks belong to the package reader/writer because they require archive or stream access.

AnkiValidationResult result = AnkiValidator.Validate(new[] { germanDeck, spanishDeck });
if (!result.IsValid)
{
throw new AnkiValidationException(result);
}
Stops serialization or package creation when a deck has structured validation errors.
Exceptions
ArgumentNullExceptionroots is null.
ArgumentExceptionroots is empty or contains a null hierarchy root.

Definition at line 72 of file AnkiValidator.cs.


The documentation for this class was generated from the following file: