您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

36 行
1.2 KiB

  1. using JT808.Protocol.Attributes;
  2. using JT808.Protocol.Enums;
  3. using JT808.Protocol.Exceptions;
  4. using JT808.Protocol.Formatters;
  5. using JT808.Protocol.Interfaces;
  6. using System;
  7. using System.Collections.Concurrent;
  8. using System.Linq.Expressions;
  9. using System.Reflection;
  10. namespace JT808.Protocol.Extensions
  11. {
  12. [Obsolete("使用JT808ConfigExtensions")]
  13. public static class JT808FormatterExtensions
  14. {
  15. public static IJT808Formatter<T> GetFormatter<T>(IJT808Config jT808Config)
  16. {
  17. return (IJT808Formatter<T>)GetFormatter(typeof(T), jT808Config);
  18. }
  19. public static IJT808MessagePackFormatter<T> GetMessagePackFormatter<T>(IJT808Config jT808Config)
  20. {
  21. return (IJT808MessagePackFormatter<T>)GetFormatter(typeof(T), jT808Config);
  22. }
  23. public static object GetFormatter(Type type,IJT808Config jT808Config)
  24. {
  25. if (!jT808Config.FormatterFactory.FormatterDict.TryGetValue(type.GUID, out var formatter))
  26. {
  27. throw new JT808Exception(JT808ErrorCode.NotGlobalRegisterFormatterAssembly, type.FullName);
  28. }
  29. return formatter;
  30. }
  31. }
  32. }