# Is it possible to get the fieldnames of a struct inside a macro?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314>\
**Category:** General Usage\
**Created:** [January 13, 2020, 8:44pm UTC](https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314 "2020-01-13T20:44:53Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [January 13, 2020, 9:05pm UTC](https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314/6 "2020-01-13T21:05:33Z")

</div>

```julia
julia> macro doit(T)
           fnames = fieldnames(eval(T))
           # better:
           # fieldnames(Core.eval( __module__ , T))
           @show fnames
       end
@doit (macro with 1 method)

julia> struct S;a;b;end

julia> @doit S
fnames = (:a, :b)
(:a, :b)

```

See also [Using eval inside macro? - #2 by yuyichao](https://discourse.julialang.org/t/using-eval-inside-macro/8183/2)

---

_[View the full topic](https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314)._
