Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

SignalRContractResolver.cs 996B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Reflection;
  3. using Microsoft.AspNetCore.SignalR.Infrastructure;
  4. using Newtonsoft.Json.Serialization;
  5. namespace Luticate2.Utils.Hubs
  6. {
  7. public class SignalRContractResolver : IContractResolver
  8. {
  9. private readonly Assembly _assembly;
  10. private readonly IContractResolver _camelCaseContractResolver;
  11. private readonly IContractResolver _defaultContractSerializer;
  12. public SignalRContractResolver()
  13. {
  14. _defaultContractSerializer = new DefaultContractResolver();
  15. _camelCaseContractResolver = new CamelCasePropertyNamesContractResolver();
  16. _assembly = typeof(Connection).GetTypeInfo().Assembly;
  17. }
  18. public JsonContract ResolveContract(Type type)
  19. {
  20. if (type.GetTypeInfo().Assembly.Equals(_assembly))
  21. return _defaultContractSerializer.ResolveContract(type);
  22. return _camelCaseContractResolver.ResolveContract(type);
  23. }
  24. }
  25. }