AgoraOptional.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Specialized;
  4. using Agora.Rtc.LitJson;
  5. namespace Agora.Rtc
  6. {
  7. public class Optional<T>
  8. {
  9. private T value;
  10. private bool hasValue;
  11. public Optional()
  12. {
  13. hasValue = false;
  14. }
  15. public bool HasValue()
  16. {
  17. return hasValue;
  18. }
  19. public T GetValue()
  20. {
  21. return this.value;
  22. }
  23. public void SetValue(T val)
  24. {
  25. this.hasValue = true;
  26. this.value = val;
  27. }
  28. public void SetEmpty()
  29. {
  30. this.hasValue = false;
  31. }
  32. }
  33. public class OptionalJsonParse
  34. {
  35. public virtual void ToJson(JsonWriter writer)
  36. {
  37. throw new NotImplementedException();
  38. }
  39. public virtual void WriteEnum(LitJson.JsonWriter writer, Object obj)
  40. {
  41. Type obj_type = obj.GetType();
  42. Type e_type = Enum.GetUnderlyingType(obj_type);
  43. if (e_type == typeof(long))
  44. writer.Write((long)obj);
  45. else if (e_type == typeof(uint))
  46. writer.Write((uint)obj);
  47. else if (e_type == typeof(ulong))
  48. writer.Write((ulong)obj);
  49. else if (e_type == typeof(ushort))
  50. writer.Write((ushort)obj);
  51. else if (e_type == typeof(short))
  52. writer.Write((short)obj);
  53. else if (e_type == typeof(byte))
  54. writer.Write((byte)obj);
  55. else if (e_type == typeof(sbyte))
  56. writer.Write((sbyte)obj);
  57. else
  58. writer.Write((int)obj);
  59. }
  60. }
  61. }