/// <inheritdoc /> public IEnumerable <T> Populate <T>(IEnumerable <T> entities, byte[] body) where T : class { var jsonStream = new RESTarStream(ContentType.JSON); try { ProduceJsonArray(new MemoryStream(body), jsonStream); return(JsonProvider.Populate(entities, jsonStream.GetBytes())); } finally { jsonStream.CanClose = true; jsonStream.Dispose(); } }
/// <summary> /// Populates the body onto each entity in a source collection. If the body is empty, /// returns null. /// </summary> public IEnumerable <T> PopulateTo <T>(IEnumerable <T> source) where T : class { if (source == null || !HasContent) { return(null); } var contentTypeProvider = ProtocolProvider.InputMimeBindings.SafeGet(ContentType.MediaType) ?? throw new UnsupportedContent(ContentType.MediaType); try { return(contentTypeProvider.Populate(source, Stream.GetBytes())); } finally { Stream.Rewind(); } }