ProtobufPropertyHelper.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ProtoBuf
  4. {
  5. public class ProtobufPropertyHelper
  6. {
  7. static ProtobufPropertyHelper m_current;
  8. static ProtobufPropertyHelper current
  9. {
  10. get
  11. {
  12. if (m_current == null)
  13. m_current = new ProtobufPropertyHelper();
  14. return m_current;
  15. }
  16. }
  17. Dictionary<string, Type> m_types = new Dictionary<string, Type>();
  18. private ProtobufPropertyHelper() { }
  19. void RegisterMemberTypeInternal(string metaIndex, Type type)
  20. {
  21. if (!m_types.ContainsKey(metaIndex))
  22. {
  23. m_types.Add(metaIndex,type);
  24. }
  25. else
  26. throw new SystemException(string.Format("PropertyMeta : {0} is registered!",metaIndex));
  27. }
  28. Type FindMemberTypeInternal(string metaIndex)
  29. {
  30. Type type = null;
  31. if (!m_types.TryGetValue(metaIndex, out type))
  32. {
  33. throw new SystemException(string.Format("PropertyMeta : {0} is not registered!", metaIndex));
  34. }
  35. return type;
  36. }
  37. public static void RegisterMemberType(string metaIndex, Type type)
  38. {
  39. current.RegisterMemberTypeInternal(metaIndex, type);
  40. }
  41. public static Type FindMemberType(string metaIndex)
  42. {
  43. return current.FindMemberTypeInternal(metaIndex);
  44. }
  45. }
  46. }