static bool TryDeserializeAdapter <TValue>(IJsonAdapter adapter, UnsafeValueView view, ref TValue value, List <DeserializationEvent> events) { if (adapter is IJsonAdapter <TValue> typed) { try { value = typed.Deserialize(view.AsSafe()); } catch (Exception e) { events.Add(new DeserializationEvent(EventType.Exception, e)); } return(true); } if (adapter is Adapters.Contravariant.IJsonAdapter <TValue> typedContravariant) { try { // @TODO Type checking on return value. value = (TValue)typedContravariant.Deserialize(view.AsSafe()); } catch (Exception e) { events.Add(new DeserializationEvent(EventType.Exception, e)); } return(true); } return(false); }
public bool TryDeserialize <TValue>(UnsafeValueView view, ref TValue value, List <DeserializationEvent> events) { if (null != UserDefined && UserDefined.Count > 0) { foreach (var adapter in UserDefined) { if (TryDeserializeAdapter(adapter, view, ref value, events)) { return(true); } } } if (null != Global && Global.Count > 0) { foreach (var adapter in Global) { if (TryDeserializeAdapter(adapter, view, ref value, events)) { return(true); } } } if (TryDeserializeAdapter(InternalAdapter, view, ref value, events)) { return(true); } #if UNITY_EDITOR if (TryDeserializeLazyLoadReference(view.AsSafe(), ref value, events)) { return(true); } #endif return(false); }