Skip to content

Haxe macro for autoimplementing toString (and other string-related tools).

License

Notifications You must be signed in to change notification settings

Frixuu/ToString

Repository files navigation

tostring

Haxe macro for automatically generating toString methods.

How to use

  • To generate the method, use this build macro (autobuild also works fine):

    @:build(tostring.ToString.generate())
  • To exclude a field from being printed out, use meta:

    @:tostring.exclude

Example

class Animal {
    public var age: Int;
    public var name: Null<String>;
    @:tostring.exclude public var momName: Null<String>;
}

@:build(tostring.ToString.generate())
class Dog extends Animal {
    @:tostring.exclude public var favoriteFood: String;
    public var breed: Breed;
    public var ageInDogYears(get, never): Int;
    public function get_ageInDogYears(): Int {
        return this.age * 7;
    }
}

Example output:

Dog { age: 6, name: Rex, breed: GoldenRetriever, ageInDogYears: 42 }

About

Haxe macro for autoimplementing toString (and other string-related tools).

Resources

License

Stars

Watchers

Forks

Releases

No releases published