Ejemplo n.º 1
0
        public static IDictionary <string, object> GetExceptionHeaderDictionary(Exception exception)
        {
            exception = exception.GetBaseException() ?? exception;

            var exceptionMessage = GetMessage(exception);

            return(new Dictionary <string, object>
            {
                { MessageHeaders.Reason, "fault" },
                { MessageHeaders.FaultExceptionType, TypeMetadataCache.GetShortName(exception.GetType()) },
                { MessageHeaders.FaultMessage, exceptionMessage },
                { MessageHeaders.FaultStackTrace, GetStackTrace(exception) }
            });
        }
Ejemplo n.º 2
0
        public object Deserialize(object value, Type objectType, bool allowNull = false)
        {
            var token = value as JToken ?? new JValue(value);

            if (token.Type == JTokenType.Null && allowNull)
            {
                return(null);
            }

            if (token.Type == JTokenType.String && objectType.IsInterface && TypeMetadataCache.IsValidMessageType(objectType))
            {
                return(JsonConvert.DeserializeObject((string)value, objectType, JsonMessageSerializer.DeserializerSettings));
            }

            using var jsonReader = new JTokenReader(token);

            return(SerializerCache.Deserializer.Deserialize(jsonReader, objectType));
        }