diff --git a/AUTHORS.md b/AUTHORS.md index 9253c7e55..679f24bb2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -64,6 +64,7 @@ - ([@OneBlue](https://github.com/OneBlue)) - ([@rico-chet](https://github.com/rico-chet)) - ([@rmadsen-ks](https://github.com/rmadsen-ks)) +- ([@SnGmng](https://github.com/SnGmng)) - ([@stonebig](https://github.com/stonebig)) - ([@testrunner123](https://github.com/testrunner123)) diff --git a/CHANGELOG.md b/CHANGELOG.md index e24a46904..5eabfe74e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. ### Added - Added automatic NuGet package generation in appveyor and local builds +- Added Dictionary to PyDict conversion to the function ToPython() ### Changed diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index e7e047419..82ff0733d 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -150,6 +150,24 @@ internal static IntPtr ToPython(object value, Type type) return resultlist.Handle; } } + else if (value is IDictionary && !(value is INotifyPropertyChanged) && value.GetType().IsGenericType) + { + using (var resultdict = new PyDict()) + { + foreach (DictionaryEntry o in (IDictionary)value) + { + using (var k = new PyObject(ToPython(o.Key, o.Key?.GetType()))) + { + using (var v = new PyObject(ToPython(o.Value, o.Value?.GetType()))) + { + resultdict.SetItem(k, v); + } + } + } + Runtime.XIncref(resultdict.Handle); + return resultdict.Handle; + } + } // it the type is a python subclass of a managed type then return the // underlying python object rather than construct a new wrapper object.