public override object?Read(string data, Type type) { _stringBuilder.Clear(); var p = ListFormat.Default.CreateParser(data, _stringBuilder); p.ParseNext(); if (string.IsNullOrEmpty(p.Item)) { // Special case: null deserialization return(null); } TypeNameHelpers.SplitAssemblyQualifiedName(p.Item, out var assemblyName, out var typeName); var actualType = _serializationBinder.BindToType(assemblyName, typeName); if (!type.IsAssignableFrom(actualType)) { throw Errors.UnsupportedTypeForJsonSerialization(actualType); } if (!Verifier.Invoke(actualType)) { throw Errors.UnsupportedTypeForJsonSerialization(actualType); } p.ParseNext(); return(UnsafeSerializer.Reader.Read(p.Item, actualType)); }
public override Type BindToType(string assemblyName, string typeName) { if (typeName.StartsWith("<>f__AnonymousType")) { return(typeof(ExpandoObject)); } return(_binder.BindToType(assemblyName, typeName)); }
public Type BindToType(string assemblyName, string typeName) { try { return(binder.BindToType(assemblyName, typeName)); } catch (Exception ex) { throw new JsonSerializationBinderException(ex.Message, ex); } }
public Type BindToType(string assemblyName, string typeName) { if (typeName == "Created" && assemblyName == null) { return(typeof(CreatedEvent)); } if (typeName == "Edited" && assemblyName == null) { return(typeof(EditedEvent)); } return(fallback.BindToType(assemblyName, typeName)); }
private bool IsTypeExplicitlyDefined(JToken token, ISerializationBinder binder, ref Type objectType) { if (token.Children <JProperty>().FirstOrDefault(_ => _.Name == "__typename") is JProperty typeToken) { typeToken.Remove(); var typeName = (string)((JValue)typeToken.Value).Value; var explicitObjectType = binder.BindToType(null, typeName) ?? throw new InvalidOperationException(string.Format(Resources.GqlMaterializer_UnableBindToType, typeName)); if (!objectType.IsAssignableFrom(explicitObjectType)) { throw new InvalidOperationException(); } objectType = explicitObjectType; return(true); } return(false); }
/// <inheritdoc /> public virtual Type BindToType(string assemblyName, string typeName) => innerBinder.BindToType(assemblyName, typeName);
public Type BindToType(string assemblyName, string typeName) { return(binder.BindToType(assemblyName, typeName)); }