namespace Cef3 { using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using Cef3.Interop; /// /// Class used to represent post data for a web request. The methods of this /// class may be called on any thread. /// public sealed unsafe partial class CefPostData { /// /// Create a new CefPostData object. /// public static CefPostData Create() { return CefPostData.FromNative( cef_post_data_t.create() ); } /// /// Returns true if this object is read-only. /// public bool IsReadOnly { get { return cef_post_data_t.is_read_only(_self) != 0; } } /// /// Returns the number of existing post data elements. /// public int Count { get { return (int)cef_post_data_t.get_element_count(_self); } } /// /// Retrieve the post data elements. /// public CefPostDataElement[] GetElements() { // FIXME: CefPostDataElement.GetElements(): check CEF C API impl var count = Count; if (count == 0) return new CefPostDataElement[0]; UIntPtr n_elementsCount = (UIntPtr)count; var n_elements = new cef_post_data_element_t*[count]; fixed (cef_post_data_element_t** n_elements_ptr = n_elements) { cef_post_data_t.get_elements(_self, &n_elementsCount, n_elements_ptr); if ((int)n_elementsCount > count) throw new InvalidOperationException(); } count = (int)n_elementsCount; var elements = new CefPostDataElement[count]; for (var i = 0; i < count; i++) { elements[i] = CefPostDataElement.FromNative(n_elements[i]); } return elements; } /// /// Remove the specified post data element. Returns true if the removal /// succeeds. /// public bool Remove(CefPostDataElement element) { return cef_post_data_t.remove_element(_self, element.ToNative()) != 0; } /// /// Add the specified post data element. Returns true if the add succeeds. /// public bool Add(CefPostDataElement element) { return cef_post_data_t.add_element(_self, element.ToNative()) != 0; } /// /// Remove all existing post data elements. /// public void RemoveAll() { cef_post_data_t.remove_elements(_self); } } }