Source
Edit
General utility macros/templates for interacting with types and instances
proc hasField[T: object | ref object](obj: T; fieldName: static string): bool {.
compileTime.}
-
Checks at compileTime whether the given object instance has a field with the name fieldName
Source
Edit
proc hasField[T: object | ref object](t: typedesc[T]; fieldName: static string): bool {.
compileTime.}
-
Checks at compileTime whether the given object type has a field with the name fieldName
Source
Edit
macro getField[T: object | ref object](obj: T; fieldName: static string): untyped
-
Accesses the field on an object instance by generating the code obj.fieldName
Source
Edit
macro getField[T: object | ref object](someType: typedesc[T];
fieldName: static string): untyped
-
Accesses the field on an object type at by generating the code obj.fieldName
Source
Edit
template setField[T: object | ref object](obj: var T; fieldName: static string;
value: untyped)
-
Sets the field on an object type to the specified value by generating the code obj.fieldName = value
Source
Edit