public static class LiteralsTurns the text of a quoted attribute into the value the property it is assigned to wants.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Variant="Subtle" reads the way an attribute should and is not a string: ControlVariant.Variant is an enum, and the markup compiler cannot know that because it resolves no types. So the emitter writes n1.Variant = Literals.Of(n1.Variant, "Subtle") and the C# compiler picks which conversion that means, from the type of the property it is about to assign.
⚠ The first argument exists to be inferred from, and is never read. There is no other way to get the target's type into a generic method — C# does not infer a type argument from what an expression is being assigned to. It is a property read, so a property whose getter does work does it once per literal attribute at build time; a property that cannot be read at all is one to write with @expr.
⚠ An overload set rather than a converter, and that is the whole design. A single object Convert(Type, string) would compile for every property and fail at run time on the ones it cannot do. Here a property of a type nothing converts to — a PathBuilder, say — is a compile error on the characters of the attribute, which is the bargain every other part of the markup channel is written to keep. It is also why this is AOT-clean: Parse``1 under a struct, Enum constraint is static generic code, not reflection over a Type.
Methods (11)
public static string Of(string? shape, string text)A property that is already text.
public static T Of<T>(T shape, string text) where T : struct, EnumAn enum-valued property, named by member rather than by qualified expression.
public static T? Of<T>(T? shape, string text) where T : struct, Enumpublic static bool Of(bool shape, string text)A flag, written as it is in C# and in CSS both.
public static bool? Of(bool? shape, string text)public static int Of(int shape, string text)A whole number.
public static int? Of(int? shape, string text)public static float Of(float shape, string text)A number.
public static float? Of(float? shape, string text)public static double Of(double shape, string text)public static double? Of(double? shape, string text)
Used by (3)
- TaskCenterVixen.Editor.Ui
- TerrainBrushInspectorVixen.Editor.Terrain
- UndoHistoryVixen.Editor.App