fork download
  1. import std.stdio;
  2. import std.json;
  3. import std.traits;
  4.  
  5. struct TestStruct
  6. {
  7. @("noserialize") int x;
  8. int y;
  9. int z;
  10. }
  11.  
  12. void serialize(T)(T obj)
  13. {
  14. if (is(T == struct))
  15. {
  16. foreach (i, member; FieldNameTuple!T)
  17. {
  18. if (!hasUDA!(member, "noserialize"))
  19. {
  20. writeln(member);
  21. }
  22. }
  23. } else {
  24. assert(0, "Not a struct");
  25. }
  26. }
  27.  
  28. void main()
  29. {
  30. TestStruct ts;
  31. ts.x = 1;
  32. ts.y = 2;
  33. ts.z = 3;
  34. serialize(ts);
  35. }
  36.  
Success #stdin #stdout 0.01s 6780KB
stdin
Standard input is empty
stdout
x
y
z