internal static IReadOnlyDictionary <Type, Serializer> IndexSerializers(IDataContractAccess dataContract) { var sortedSerializers = dataContract .Serializers .OrderByDescending(x => x, new SerializerComparer()) .ToList(); return(dataContract .Routes .Select(x => x.DataType) .Distinct() .Where(x => x != typeof(void)) .ToDictionary( x => x, x => FindSerializer(sortedSerializers, x))); Serializer FindSerializer(List <Serializer> serializers, Type targetType) { var serializer = serializers.FirstOrDefault(x => !x.IsGeneral && targetType == x.TargetType); if (serializer != null) { return(serializer); } serializer = serializers.First(x => x.IsGeneral && targetType.IsSameOrSubclass(x.TargetType)); return(serializer.ToTypeSerializer(targetType)); } }
internal static IReadOnlyDictionary <string, Route> IndexRoutes(IDataContractAccess dataContract) { return(dataContract .Routes .ToDictionary( x => x.Name, x => x)); }
internal static IReadOnlyDictionary <string, List <Subscriber> > IndexSubscribers(IDataContractAccess dataContract) { return(dataContract .Subscribers .GroupBy(x => x.Incoming.Name) .ToDictionary( x => x.Key, x => x.ToList())); }
public DataContractManager(IDataContractAccess dataContract) { _routes = IndexRoutes(dataContract); _subscribers = IndexSubscribers(dataContract); _serializers = IndexSerializers(dataContract); }