@@ -181,7 +181,31 @@ public bool HasAttr(PyObject name)
181181 {
182182 return Runtime . PyObject_HasAttr ( obj , name . obj ) != 0 ;
183183 }
184-
184+
185+ /// <summary>
186+ /// GetAttr Method For Dynamic Type
187+ /// </summary>
188+ /// <remarks>
189+ /// Returns the named attribute of the Python object, or raises a
190+ /// PythonException if the attribute access fails.
191+ /// </remarks>
192+ public object GetAttrDynamic ( string name )
193+ {
194+ IntPtr op = Runtime . PyObject_GetAttrString ( obj , name ) ;
195+ if ( op == IntPtr . Zero )
196+ {
197+ throw new PythonException ( ) ;
198+ }
199+ if ( ManagedType . IsManagedType ( op ) )
200+ {
201+ ManagedType managedMethod = ManagedType . GetManagedObject ( op ) ;
202+ if ( managedMethod is CLRObject )
203+ {
204+ return ( ( CLRObject ) managedMethod ) . inst ;
205+ }
206+ }
207+ return CheckNone ( new PyObject ( op ) ) ;
208+ }
185209
186210 /// <summary>
187211 /// GetAttr Method
@@ -891,7 +915,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
891915 {
892916 if ( this . HasAttr ( binder . Name ) )
893917 {
894- result = CheckNone ( this . GetAttr ( binder . Name ) ) ;
918+ result = this . GetAttrDynamic ( binder . Name ) ;
895919 return true ;
896920 }
897921 else
@@ -904,7 +928,15 @@ public override bool TrySetMember(SetMemberBinder binder, object value)
904928 {
905929 if ( this . HasAttr ( binder . Name ) )
906930 {
907- this . SetAttr ( binder . Name , ( PyObject ) value ) ;
931+ if ( value is PyObject )
932+ {
933+ this . SetAttr ( binder . Name , ( PyObject ) value ) ;
934+ }
935+ else
936+ {
937+ var ptr = CLRObject . GetInstHandle ( value , value . GetType ( ) ) ;
938+ this . SetAttr ( binder . Name , new PyObject ( ptr ) ) ;
939+ }
908940 return true ;
909941 }
910942 else
0 commit comments