src/norm/pragmasutils

    Dark Mode
Search:
Group by:

Pragmas in develop branch post 1.6 to be able to use generic Model <model.html#Model>.

Macros

macro getCustomPragmaVal(n: typed; cp: typed{nkSym}): untyped

Expands to value of custom pragma cp of expression n which is expected to be nnkDotExpr, a proc or a type.

See also hasCustomPragma

template serializationKey(key: string) {.pragma.}
type
  MyObj {.serializationKey: "mo".} = object
    myField {.serializationKey: "mf".}: int
var o: MyObj
assert(o.myField.getCustomPragmaVal(serializationKey) == "mf")
assert(o.getCustomPragmaVal(serializationKey) == "mo")
assert(MyObj.getCustomPragmaVal(serializationKey) == "mo")
macro hasCustomPragma(n: typed; cp: typed{nkSym}): untyped

Expands to true if expression n which is expected to be nnkDotExpr (if checking a field), a proc or a type has custom pragma cp.

See also getCustomPragmaVal.

template myAttr() {.pragma.}
type
  MyObj = object
    myField {.myAttr.}: int

proc myProc() {.myAttr.} = discard

var o: MyObj
assert(o.myField.hasCustomPragma(myAttr))
assert(myProc.hasCustomPragma(myAttr))