private MessagingEnvelope <JObject> DeserializePartialEnvelope(string envelopeString, out Type concreteType, MessageSerDesOptions serDesOptions, Type expectedType = null) { var partialEnvelope = JsonConvert.DeserializeObject <MessagingEnvelope <JObject> >(envelopeString); if (serDesOptions.DeserializationType == DeserializationType.HeadersOnly) { concreteType = null; return(partialEnvelope); } var messageTypeId = partialEnvelope.GetMessageTypeId(); if (messageTypeId == null) { if (expectedType == null || expectedType.IsAbstract || expectedType.IsInterface) { throw new Exception("Type information was not found in MessageType header"); } concreteType = expectedType; return(partialEnvelope); } concreteType = _messageTypeRegistry.ResolveType(messageTypeId, serDesOptions.DynamicDeserializationScannedAssemblies); if (expectedType != null && !expectedType.IsAssignableFrom(concreteType)) { throw new Exception($"Incompatible types: expected {expectedType} and found {concreteType}"); } return(partialEnvelope); }
private (MessagingEnvelope <JObject> envelope, Type runtimeType) DeserializePartialEnvelope( string envelopeString, Type expectedType = null, MessageSerDesOptions options = null) { options ??= MessageSerDesOptions.Default; var partialEnvelope = JsonConvert.DeserializeObject <MessagingEnvelope <JObject> >(envelopeString); if (!options.UseDynamicDeserialization) { return(partialEnvelope, null); } var messageTypeId = partialEnvelope.GetMessageTypeId(); if (messageTypeId == null) { if (expectedType == null || expectedType.IsAbstract || expectedType.IsInterface) { throw new Exception("Type information was not found in MessageType header"); } return(partialEnvelope, null); } var runtimeType = _messageTypeRegistry.ResolveType(messageTypeId, options.DynamicDeserializationScannedAssemblies); if (runtimeType == null) { return(partialEnvelope, null); } if (expectedType != null && !expectedType.IsAssignableFrom(runtimeType)) { throw new Exception($"Incompatible types: expected {expectedType} and found {runtimeType}"); } return(partialEnvelope, runtimeType); }