AvatarOptions Class

Provides options used to generate an avatar SVG.

public class AvatarOptions

Constructors

NameDescription
AvatarOptions()Initializes a new instance of the AvatarOptions class.

AvatarOptions()

AvatarOptions.cs

Initializes a new instance of the AvatarOptions class.

public AvatarOptions()

Properties

NameDescription
AccessibleLabelGets or sets the text announced by assistive technologies. If null, the bigram is used.
BigramGets or sets the explicit bigram to render. If null, the bigram is extracted from the name.
IsDecorativeGets or sets a value indicating whether the avatar is purely decorative and should be hidden from assistive technologies. The default is false.
PaletteGets the mutable list of colors used for rendering.
ShapeGets or sets the shape of the avatar.
SizeGets or sets the size of the generated SVG in pixels.

AccessibleLabel

AvatarOptions.cs

Gets or sets the text announced by assistive technologies. If null, the bigram is used.

public string? AccessibleLabel { get; set; }

Property value

string?

Remarks

Set this to the full name so the avatar announces as "John Doe" rather than "JD". Characters that are invalid in an XML document are removed, so an untrusted display name can be passed directly. Ignored when AvatarOptions.IsDecorative is true.

Gets or sets the explicit bigram to render. If null, the bigram is extracted from the name.

public string? Bigram { get; set; }

Property value

string?

Remarks

The value must contain 1 or 2 grapheme clusters, no whitespace, and no character that is invalid in an XML document. It does not affect the selected color, which always derives from the name.

IsDecorative

AvatarOptions.cs

Gets or sets a value indicating whether the avatar is purely decorative and should be hidden from assistive technologies. The default is false.

public bool IsDecorative { get; set; }

Property value

bool

Remarks

Set this when the avatar sits next to the name it represents, so the name is not announced twice. The generated element uses aria-hidden instead of role and aria-label.

Gets the mutable list of colors used for rendering.

public IList<AvatarColorPair> Palette { get; }

Property value

IList<AvatarColorPair>

Remarks

The color is selected with hash(name) % Palette.Count, so the number of entries and their order are part of the name-to-color mapping: adding or removing one entry re-colors nearly every name. This instance is not thread-safe; do not mutate it while AvatarGenerator.CreateSvg is running.

Gets or sets the shape of the avatar.

public AvatarShape Shape { get; set; }

Property value

AvatarShape

Gets or sets the size of the generated SVG in pixels.

public int Size { get; set; }

Property value

int

Constants

NameDescription
DefaultSizeThe default avatar size (64x64).

DefaultSize

The default avatar size (64x64).

public const int DefaultSize = 64