| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f60dc32 commit 545c549
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ | |||
| 28 | 28 | - Jeff Reback ([@jreback](https://github.com/jreback)) | |
| 29 | 29 | - Joe Frayne ([@jfrayne](https://github.com/jfrayne)) | |
| 30 | 30 | - John Burnett ([@johnburnett](https://github.com/johnburnett)) | |
| 31 | + - John Wilkes ([@jbw3](https://github.com/jbw3)) | ||
| 31 | 32 | - Luke Stratman ([@lstratman](https://github.com/lstratman)) | |
| 32 | 33 | - Konstantin Posudevskiy ([@konstantin-posudevskiy](https://github.com/konstantin-posudevskiy)) | |
| 33 | 34 | - Matthias Dittrich ([@matthid](https://github.com/matthid)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 16 | 16 | - Added `clr.GetClrType` (#432, #433) | |
| 17 | 17 | - Allowed passing `None` for nullable args (#460) | |
| 18 | 18 | - Added keyword arguments based on C# syntax for calling CPython methods (#461) | |
| 19 | + - Implemented GetDynamicMemberNames() for PyObject to allow dynamic object members to be visible in the debugger (#443) | ||
| 19 | 20 | ||
| 20 | 21 | ### Changed | |
| 21 | 22 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,6 +93,7 @@ | |||
| 93 | 93 | <Compile Include="TestPyList.cs" /> | |
| 94 | 94 | <Compile Include="TestPyLong.cs" /> | |
| 95 | 95 | <Compile Include="TestPyNumber.cs" /> | |
| 96 | + <Compile Include="TestPyObject.cs" /> | ||
| 96 | 97 | <Compile Include="TestPySequence.cs" /> | |
| 97 | 98 | <Compile Include="TestPyString.cs" /> | |
| 98 | 99 | <Compile Include="TestPythonException.cs" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,61 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Linq; | ||
| 4 | + using NUnit.Framework; | ||
| 5 | + using Python.Runtime; | ||
| 6 | + | ||
| 7 | + namespace Python.EmbeddingTest | ||
| 8 | + { | ||
| 9 | + public class TestPyObject | ||
| 10 | + { | ||
| 11 | + [OneTimeSetUp] | ||
| 12 | + public void SetUp() | ||
| 13 | + { | ||
| 14 | + PythonEngine.Initialize(); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + [OneTimeTearDown] | ||
| 18 | + public void Dispose() | ||
| 19 | + { | ||
| 20 | + PythonEngine.Shutdown(); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + [Test] | ||
| 24 | + public void TestGetDynamicMemberNames() | ||
| 25 | + { | ||
| 26 | + List<string> expectedMemberNames = new List<string> | ||
| 27 | + { | ||
| 28 | + "add", | ||
| 29 | + "getNumber", | ||
| 30 | + "member1", | ||
| 31 | + "member2" | ||
| 32 | + }; | ||
| 33 | + | ||
| 34 | + PyDict locals = new PyDict(); | ||
| 35 | + | ||
| 36 | + PythonEngine.Exec(@" | ||
| 37 | + class MemberNamesTest(object): | ||
| 38 | + def __init__(self): | ||
| 39 | + self.member1 = 123 | ||
| 40 | + self.member2 = 'Test string' | ||
| 41 | + | ||
| 42 | + def getNumber(self): | ||
| 43 | + return 123 | ||
| 44 | + | ||
| 45 | + def add(self, x, y): | ||
| 46 | + return x + y | ||
| 47 | + | ||
| 48 | + a = MemberNamesTest() | ||
| 49 | + ", null, locals.Handle); | ||
| 50 | + | ||
| 51 | + PyObject a = locals.GetItem("a"); | ||
| 52 | + | ||
| 53 | + IEnumerable<string> memberNames = a.GetDynamicMemberNames(); | ||
| 54 | + | ||
| 55 | + foreach (string expectedName in expectedMemberNames) | ||
| 56 | + { | ||
| 57 | + Assert.IsTrue(memberNames.Contains(expectedName), "Could not find member '{0}'.", expectedName); | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Collections; | |
| 3 | + using System.Collections.Generic; | ||
| 3 | 4 | using System.Dynamic; | |
| 4 | 5 | using System.Linq.Expressions; | |
| 5 | 6 | ||
@@ -1238,5 +1239,20 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out object r | |||
| 1238 | 1239 | result = CheckNone(new PyObject(res)); | |
| 1239 | 1240 | return true; | |
| 1240 | 1241 | } | |
| 1242 | + | ||
| 1243 | + /// <summary> | ||
| 1244 | + /// Returns the enumeration of all dynamic member names. | ||
| 1245 | + /// </summary> | ||
| 1246 | + /// <remarks> | ||
| 1247 | + /// This method exists for debugging purposes only. | ||
| 1248 | + /// </remarks> | ||
| 1249 | + /// <returns>A sequence that contains dynamic member names.</returns> | ||
| 1250 | + public override IEnumerable<string> GetDynamicMemberNames() | ||
| 1251 | + { | ||
| 1252 | + foreach (PyObject pyObj in Dir()) | ||
| 1253 | + { | ||
| 1254 | + yield return pyObj.ToString(); | ||
| 1255 | + } | ||
| 1256 | + } | ||
| 1241 | 1257 | } | |
| 1242 | 1258 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments