private static ListenerSettings FromNativeObject(AGDnsApi.ag_listener_settings listenerSettingsC) { IPAddress address = CreateIpAddress(listenerSettingsC.address); int port = listenerSettingsC.port; IPEndPoint endPoint = CreateEndPoint(address, port); ListenerSettings listenerSettings = new ListenerSettings { EndPoint = endPoint }; MarshalUtils.CopyFieldsToProperties(listenerSettingsC, listenerSettings); return(listenerSettings); }
/// <summary> /// Converts the managed <see cref="listenerSettings"/> /// (<seealso cref="ListenerSettings"/>) to the native <see cref="AGDnsApi.ag_listener_settings"/> object /// </summary> /// <param name="listenerSettings"><see cref="ListenerSettings"/> instance to convert</param> /// <param name="allocatedPointers">List of pointers, which were allocated. /// Pointers, which will be referred to a newly allocated memory /// (within the process of marshaling the string to the pointer) /// will be added to this list. /// If this list is not specified (null), /// a new created pointer will not be added anywhere</param> /// The resulting pointer (<seealso cref="IntPtr"/>) must be freed /// with <see cref="MarshalUtils.SafeFreeHGlobal(IntPtr)"/>> /// <returns>An instance of <see cref="AGDnsApi.ag_listener_settings"/></returns> private static AGDnsApi.ag_listener_settings ToNativeObject( ListenerSettings listenerSettings, Queue <IntPtr> allocatedPointers) { ushort port = (ushort)listenerSettings.EndPoint.Port; IntPtr address = MarshalUtils.StringToPtr( listenerSettings.EndPoint.Address.ToString(), allocatedPointers); AGDnsApi.ag_listener_settings listenerSettingsC = new AGDnsApi.ag_listener_settings { address = address, port = port }; MarshalUtils.CopyPropertiesToFields(listenerSettings, ref listenerSettingsC); return(listenerSettingsC); }