StringStringConverter.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*********************************************************************************
  2. *Author: OnClick
  3. *Version: 0.0.1
  4. *UnityVersion: 2018.3.11f1
  5. *Date: 2019-04-07
  6. *Description: IFramework
  7. *History: 2018.11--
  8. *********************************************************************************/
  9. namespace IFramework.Serialization
  10. {
  11. #pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
  12. [System.Runtime.InteropServices.ComVisible(false)]
  13. public class StringStringConverter : StringConverter<string>
  14. {
  15. const string flag="\"";
  16. public override bool TryConvert(string self, out string result)
  17. {
  18. if (!self.StartsWith(flag) || !self.EndsWith(flag))
  19. {
  20. result = self;
  21. return true;
  22. }
  23. else
  24. {
  25. self = self.Remove(0, 1);
  26. self = self.Remove(self.Length - 1, 1);
  27. result = self;
  28. return true;
  29. }
  30. }
  31. public override string ConvertToString(string t)
  32. {
  33. return $"{flag}{t}{flag}";
  34. }
  35. }
  36. #pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
  37. }