# Macro to generate function calls from TypeDef

**URL:** <https://community.haxe.org/t/macro-to-generate-function-calls-from-typedef/1125>\
**Category:** Haxe\
**Created:** [September 28, 2018, 7:01pm UTC](https://community.haxe.org/t/macro-to-generate-function-calls-from-typedef/1125 "2018-09-28T19:01:55Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Simn](https://community.haxe.org/user_avatar/community.haxe.org/simn/32/388_2.png) [@Simn](https://community.haxe.org/u/Simn)\
**Post date:** [October 9, 2018, 10:10am UTC](https://community.haxe.org/t/macro-to-generate-function-calls-from-typedef/1125/9 "2018-10-09T10:10:04Z")

</div>

The conversion is fair enough because you have to go from expression to type somehow. There are multiple avenues here, and going through `Context.getType` is fine.

What isn’t fine is that EnumValuesTools usage. Don’t use that, use normal switches. You can simplify your code like so:

```haxe
import haxe.macro.Context;
import haxe.macro.Expr;

using haxe.macro.Tools;

class Macros {
    macro public static function build(td:Expr):Array<Field> {
        var t = Context.getType(td.toString()).follow();
		var anon = switch (t) {
			case TAnonymous(ref): ref.get();
			case _: Context.error("Structure expected", td.pos);
		}
        for (tdf in anon.fields) {
            trace('generate function: resolve_${tdf.name};');
        }

        return null;
    }
}

```

---

_[View the full topic](https://community.haxe.org/t/macro-to-generate-function-calls-from-typedef/1125)._
