public IntPtr ToUnmanaged() { var customQueryUnmanaged = new CAPI.ovrMatchmakingCustomQueryData(); if (criteria != null && criteria.Length > 0) { customQueryUnmanaged.criterionArrayCount = (uint)criteria.Length; var temp = new CAPI.ovrMatchmakingCriterion[criteria.Length]; for (int i = 0; i < criteria.Length; i++) { temp[i].importance_ = criteria[i].importance; temp[i].key_ = criteria[i].key; if (criteria[i].parameters != null && criteria[i].parameters.Count > 0) { temp[i].parameterArrayCount = (uint)criteria[i].parameters.Count; temp[i].parameterArray = CAPI.ArrayOfStructsToIntPtr(CAPI.DictionaryToOVRKeyValuePairs(criteria[i].parameters)); } else { temp[i].parameterArrayCount = 0; temp[i].parameterArray = IntPtr.Zero; } } customQueryUnmanaged.criterionArray = CAPI.ArrayOfStructsToIntPtr(temp); } else { customQueryUnmanaged.criterionArrayCount = 0; customQueryUnmanaged.criterionArray = IntPtr.Zero; } if (data != null && data.Count > 0) { customQueryUnmanaged.dataArrayCount = (uint)data.Count; customQueryUnmanaged.dataArray = CAPI.ArrayOfStructsToIntPtr(CAPI.DictionaryToOVRKeyValuePairs(data)); } else { customQueryUnmanaged.dataArrayCount = 0; customQueryUnmanaged.dataArray = IntPtr.Zero; } IntPtr res = Marshal.AllocHGlobal(Marshal.SizeOf(customQueryUnmanaged)); Marshal.StructureToPtr(customQueryUnmanaged, res, true); return(res); }