StringConverter.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*********************************************************************************
  2. *Author: OnClick
  3. *Version: 0.0.1
  4. *UnityVersion: 2018.3.11f1
  5. *Date: 2019-05-03
  6. *Description: IFramework
  7. *History: 2018.11--
  8. *********************************************************************************/
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Text;
  12. namespace IFramework.Serialization
  13. {
  14. #pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
  15. public abstract class StringConverter
  16. {
  17. public abstract string ConvertToString(object t);
  18. public abstract bool TryConvertObject(string str, out object result);
  19. }
  20. public abstract class StringConverter<T> : StringConverter
  21. {
  22. public virtual string ConvertToString(T t)
  23. {
  24. return t.ToString();
  25. }
  26. public abstract bool TryConvert(string self, out T result);
  27. public override bool TryConvertObject(string str, out object result)
  28. {
  29. T t;
  30. if (TryConvert(str, out t))
  31. {
  32. result = t;
  33. return true;
  34. }
  35. else
  36. {
  37. result = default(T);
  38. return false;
  39. }
  40. }
  41. public override string ConvertToString(object t)
  42. {
  43. return ConvertToString((T)t);
  44. }
  45. }
  46. }