StackFormatter.cs 923 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Text;
  4. namespace IFramework.Serialization
  5. {
  6. public class StackFormatter<T> : StringFormatter<Stack<T>>
  7. {
  8. public override void ConvertToString(Stack<T> t, StringBuilder builder)
  9. {
  10. ListFormatter<T> c = StringConvert.GetFormatter(typeof(List<T>)) as ListFormatter<T>;
  11. c.ConvertToString(t.ToList(), builder);
  12. }
  13. public override bool TryConvert(string self, out Stack<T> result)
  14. {
  15. ListFormatter<T> c = StringConvert.GetFormatter(typeof(List<T>)) as ListFormatter<T>;
  16. List<T> list;
  17. if (!c.TryConvert(self, out list))
  18. {
  19. result = MakeDefault();
  20. return false;
  21. }
  22. else
  23. {
  24. result = new Stack<T>(list);
  25. return true;
  26. }
  27. }
  28. }
  29. }