/// <summary> /// Deserialization constructor. /// </summary> /// <param name="info">SerializationInfo.</param> /// <param name="context">StreamingContext.</param> public WebServiceResponse(SerializationInfo info, StreamingContext context) { ReturnType = (EWebServiceReturnType)info.GetValue(nameof(ReturnType), typeof(EWebServiceReturnType)); switch (ReturnType) { case EWebServiceReturnType.ReturnVoid: break; case EWebServiceReturnType.ExceptionThrown: ReturnValueType = info.GetString(nameof(ReturnValueType)); returnValueType = Type.GetType(ReturnValueType); StringifiedException = info.GetString(nameof(StringifiedException)); try { ExceptionThrown = (Exception)info.GetValue(nameof(ExceptionThrown), returnValueType); } catch (Exception e) { ExceptionThrown = new SerializationException($"Failed to deserialize Exception of Type '{ReturnValueType}'. Information about the original Exception:\n\"{StringifiedException}\".\nException in when trying to deserialize:\n\"{e.ToString()}\"."); } break; case EWebServiceReturnType.ReturnValue: ReturnValueType = info.GetString(nameof(ReturnValueType)); returnValueType = Type.GetType(ReturnValueType); ReturnValue = info.GetValue(nameof(ReturnValue), returnValueType); break; default: throw new NotImplementedException($"Unhandled case: {nameof(ReturnType)} is '{ReturnType}'."); } }
/// <inheritdoc /> public void ReadXml(XmlReader reader) { reader.ReadStartElement(); reader.ReadStartElement(nameof(WebServiceResponse)); reader.ReadStartElement(nameof(ReturnType)); ReturnType = reader.ReadElement <EWebServiceReturnType>(); reader.ReadToEndElement(nameof(ReturnType)); switch (ReturnType) { case EWebServiceReturnType.ReturnVoid: break; case EWebServiceReturnType.ExceptionThrown: reader.ReadStartElement(nameof(ReturnValueType)); ReturnValueType = reader.ReadElement <string>(); returnValueType = Type.GetType(ReturnValueType); reader.ReadToEndElement(nameof(ReturnValueType)); reader.ReadStartElement(nameof(StringifiedException)); StringifiedException = reader.ReadElement <string>(); reader.ReadToEndElement(nameof(StringifiedException)); try { reader.ReadStartElement(nameof(ExceptionThrown)); ExceptionThrown = (Exception)reader.ReadElement(returnValueType); reader.ReadToEndElement(nameof(ExceptionThrown)); } catch (Exception e) { ExceptionThrown = new SerializationException($"Failed to deserialize Exception of Type '{ReturnValueType}'. Information about the original Exception:\n\"{StringifiedException}\".\nException in when trying to deserialize:\n\"{e.ToString()}\"."); } break; case EWebServiceReturnType.ReturnValue: reader.ReadStartElement(nameof(ReturnValueType)); ReturnValueType = reader.ReadElement <string>(); returnValueType = Type.GetType(ReturnValueType); reader.ReadToEndElement(nameof(ReturnValueType)); reader.ReadStartElement(nameof(ReturnValue)); ReturnValue = reader.ReadElement(returnValueType); reader.ReadToEndElement(nameof(ReturnValue)); break; default: throw new NotImplementedException($"Unhandled case: {nameof(ReturnType)} is '{ReturnType}'."); } reader.ReadToEndElement(nameof(WebServiceResponse)); reader.ReadEndElement(); }