vibe.d beta banner
get vibe.d
0.10.1

Asynchronous I/O that doesn’t get in your way, written in D

Function byName

Attribute for forcing serialization of enum fields by name instead of by value.

ByNameAttribute!Policy byName(alias Policy)() @property;

Example

enum Color {
	red,
	green,
	blue
}

struct Test {
	// serialized as an int (e.g. 1 for Color.green)
	Color color;
	// serialized as a string (e.g. "green" for Color.green)
	@byName Color namedColor;
	// serialized as array of ints
	Color[] colorArray;
	// serialized as array of strings
	@byName Color[] namedColorArray;
}
Authors

Sönke Ludwig

Copyright

© 2013-2016 rejectedsoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.