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

Represents one study direction generated from an AnkiNote. More...

Public Member Functions

 AnkiCard (long id, long noteId, long deckId, int templateOrdinal, AnkiScheduling scheduling)
 Initializes an unattached card for an importer or format adapter.

Properties

long Id [get]
 Gets the persisted identity Anki uses to distinguish this card from every other card.
long NoteId [get]
 Gets the ID of the note whose fields and template render this card.
long DeckId [get, set]
 Gets or sets the deck in which Anki should place this individual card.
int TemplateOrdinal [get]
 Gets which template or Cloze deletion generated this card.
AnkiScheduling Scheduling [get, set]
 Gets or replaces the complete persisted scheduler state for this card.
int Flag [get, set]
 Gets or sets the single user-visible color flag attached to this card.
IList< AnkiReviewLogReviewHistory = new List<AnkiReviewLog>() [get]
 Gets answer events associated with this card.

Detailed Description

Represents one study direction generated from an AnkiNote.

A note stores facts; a card is the question/answer view Anki schedules. A Basic note normally owns one card, a Basic-and-reversed note owns two, and a Cloze note owns one card per distinct positive cloze index. Most callers should obtain cards from AnkiNote.Cards after adding a note to a deck instead of constructing cards directly.

DeckId, Scheduling, Flag, and ReviewHistory are mutable advanced state. AnkiIO does not run Anki's scheduler; it only models and validates persisted values. Call AnkiValidator.Validate(AnkiDeck) before export. Instances and their history lists are not thread-safe.

var deck = new AnkiDeck("Vocabulary");
var note = deck.AddBasicNote("Haus", "house");
var card = note.Cards.Single();
card.Flag = 1; // red: a card-level reminder to revisit this item
Builds one named deck hierarchy and acts as the root for validation and export.
Definition AnkiDeck.cs:31

Definition at line 23 of file AnkiCard.cs.

Constructor & Destructor Documentation

◆ AnkiCard()

AnkiIO.AnkiCard.AnkiCard ( long id,
long noteId,
long deckId,
int templateOrdinal,
AnkiScheduling scheduling )
inline

Initializes an unattached card for an importer or format adapter.

Parameters
idThe persisted card ID. It must be unique across the exported graph.
noteIdThe ID of the note that generated this card.
deckIdThe ID of the deck in which Anki should place this card.
templateOrdinalFor a standard note type, the zero-based index in AnkiNoteType.Templates. For Cloze, cloze marker c1 maps to ordinal 0, c2 to ordinal 1, and so on.
schedulingNon-null persisted scheduler state. Use AnkiScheduling.New unless importing verified existing state. The object is retained by reference rather than copied.

This constructor does not attach the card to a note or deck. Ordinary creation through AnkiDeck.AddNote establishes those relationships and assigns safe new-card scheduling automatically.

Exceptions
ArgumentOutOfRangeExceptiontemplateOrdinal is negative.
ArgumentNullExceptionscheduling is null.

Definition at line 45 of file AnkiCard.cs.

Property Documentation

◆ DeckId

long AnkiIO.AnkiCard.DeckId
getset

Gets or sets the deck in which Anki should place this individual card.

A deck ID, normally the ID of the deck that owns the note.

Anki permits sibling cards from one note to live in different decks. Changing this value models that placement; it does not move the note between AnkiDeck.Notes collections or create a missing deck. Validate the complete graph before export so the referenced deck can be checked.

Definition at line 75 of file AnkiCard.cs.

◆ Flag

int AnkiIO.AnkiCard.Flag
getset

Gets or sets the single user-visible color flag attached to this card.

Anki's numeric flag code; valid persisted values are 0 through 7 and a new card starts at 0.

Flags are card-level reminders shown during review and in the browser; unlike note tags, flagging one sibling does not flag the others. Anki lets users rename flag labels, but the persisted numeric/color mapping remains:

ValueDefault flag
0No flag
1Red
2Orange
3Green
4Blue
5Pink
6Turquoise
7Purple

The legacy card column stores the flag in its low three bits. The setter deliberately accepts an int so importers can represent malformed source data and obtain a complete diagnostic report; it does not silently mask high bits. AnkiValidator.Validate(AnkiDeck) reports ANKI032 for values outside 0-7, and validated writers refuse to export that graph. Validate after assigning imported state.

Use tags when an annotation should apply to every card generated by a note or when multiple labels are needed; a card can have only one flag.

Definition at line 127 of file AnkiCard.cs.

◆ Id

long AnkiIO.AnkiCard.Id
get

Gets the persisted identity Anki uses to distinguish this card from every other card.

The fixed ID supplied by an importer or generated by AnkiIO.

Preserve this value during updates so Anki can recognize the same card. Supplying explicit IDs makes collision avoidance the caller's responsibility; AnkiValidator reports duplicate card IDs in a deck graph.

Definition at line 62 of file AnkiCard.cs.

◆ NoteId

long AnkiIO.AnkiCard.NoteId
get

Gets the ID of the note whose fields and template render this card.

A fixed note ID that should match an AnkiNote.Id in the same object graph.

Definition at line 66 of file AnkiCard.cs.

◆ ReviewHistory

IList<AnkiReviewLog> AnkiIO.AnkiCard.ReviewHistory = new List<AnkiReviewLog>()
get

Gets answer events associated with this card.

A live mutable list owned by the card; append records in chronological or persisted ID order.

Native AnkiIO JSON preserves this list and the legacy package writer emits it. The current legacy APKG reader does not reconstruct existing review-log rows, so APKG read-modify-write is not a lossless history migration. Adding a log does not update Scheduling automatically, and changing scheduling does not synthesize a log. Treat both as advanced imported state and keep them consistent yourself.

Definition at line 137 of file AnkiCard.cs.

◆ Scheduling

AnkiScheduling AnkiIO.AnkiCard.Scheduling
getset

Gets or replaces the complete persisted scheduler state for this card.

A non-null immutable value object; generated cards start with AnkiScheduling.New.

Replace this only when importing or deliberately preserving known scheduling data. Queue/type combinations and the units of AnkiScheduling.Due vary by state. AnkiIO validates combinations but does not calculate the next interval, apply deck options, or run FSRS.

Exceptions
ArgumentNullExceptionThe assigned value is null.

Definition at line 95 of file AnkiCard.cs.

◆ TemplateOrdinal

int AnkiIO.AnkiCard.TemplateOrdinal
get

Gets which template or Cloze deletion generated this card.

A fixed zero-based template index for standard notes, or one less than the positive Cloze index for Cloze notes.

For example, the second template and {{c2::answer}} both use ordinal 1. An ordinal outside the note type's available templates or current cloze indexes represents stale/corrupt state and is rejected by validation.

Definition at line 85 of file AnkiCard.cs.


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