FencedCodeBlock
Models & Types · AiDotNet.Evolution.Programs
One fenced code block found in a model response.
For Beginners
When a chat model shows you code it usually wraps it in triple backticks, often with a language name right after the opening backticks. This object is one such wrapped block: the language name that was written, the code inside, and where in the answer it appeared. Keeping every block rather than only the first lets a caller choose sensibly when the model shows an example before the real answer.
How It Works
A fence opens with three or more backticks or tildes and closes with a run of at least the same length of the
same character, which is what allows a four-backtick fence to contain three-backtick fences without being cut
short. Label is the info string that follows the opening run, lowercased and trimmed, and
Language is that label resolved through ProgramLanguageDetector when it is
recognized.
Constructors
| Constructor | Summary |
|---|---|
FencedCodeBlock(string label, string content, int startLine, int fenceLength) |
Initializes a fenced code block. |
Properties
| Property | Summary |
|---|---|
ProgramLanguage? Language { get; } |
Gets the language the label resolves to, or null when the label is missing or unknown. |
bool IsUnlabeled { get; } |
Gets whether the fence carried no info string. |
int FenceLength { get; } |
Gets the number of fence characters in the opening run. |
int StartLine { get; } |
Gets the one-based response line of the opening fence. |
string Content { get; } |
Gets the code between the fences. |
string Label { get; } |
Gets the trimmed info string that followed the opening fence, or an empty string. |
Methods
| Method | Summary |
|---|---|
string ToString() |
Returns the label and content size without echoing the code. |