Thanks, Mark. That's all really good stuff, and essentially we are already doing the same things in our app.<br><br>Where the problem comes in for me (I've narrowed it down a little bit) is that the IronPython binding code looks for a method called "SetMember" when I attempt to set an attribute. My class happens to have multiple overridden SetMember methods (which have nothing to do with Python, but make sense in my application domain), which causes Type.GetMethod() to throw an exception.<br>
<br>I logged an issue in CodePlex (<a href="http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=26277">Item #<span id="ctl00_ctl00_MasterContent_RightSideBar_WorkItemDetailsControl_DetailsSidebar_IssueIdLabel">26277: </span><span id="ctl00_ctl00_MasterContent_Content_TitlePanel"><span id="ctl00_ctl00_MasterContent_Content_TitleLabel" class="CodePlexPageHeader">CLR class with overridden SetMember method causes "Ambiguous match found"</span></span></a>); you can take a look if you want to see the whole issue and how to repro.<br>
<br><div class="gmail_quote">On Wed, Feb 17, 2010 at 9:58 AM, Mark Grice <span dir="ltr"><<a href="mailto:markjoel60@gmail.com">markjoel60@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'm not sure if this helps, but I use a C# class in my IronPython, and it works fine.<div><br></div><div>Class is defined using the shorthand get; set;</div><div><br></div><div>ie:</div><div><br></div><div><div>public class ScreenTags</div>
<div> {</div></div><div><div> public String appWindowName { get; set; }</div><div> public String fieldName { get; set; }</div><div> public bool isDataField { get; set; }</div><div> public bool isManual { get; set; }</div>
<div> public String screenLabel { get; set; }</div><div> public String description { get; set; }</div><div>}</div><div><br></div><div>(In actuality, it is a lot more than this, consisting of other classes, methods, etc...)</div>
<div><br></div><div>Now, it may be bad practice, but I then simply use an object reference in Python, and assume it was instantiated. In other words, as far as Python is concerned, there is an instantiated object of ScreenTags called "screen".</div>
<div><br></div><div>Python simply calls this whenever it wants to do something: </div><div><br></div><div>ie. screen. appWindowName = "ThisName"</div><div><br></div><div>I create the screen object in my C# code, and then add it as a reference to the python scope before I call the IronPython engine. So, on the C# side I:</div>
<div><br></div><div><div> scptEngine = Python.CreateEngine();</div><div> scptRuntime = scptEngine.Runtime;</div><div> scptScope = scptEngine.CreateScope();</div><div> AddAssemblies(scptRuntime); // call if you need to add other libraries, such as my class</div>
<div><br></div><div>And before I actually call the Engine, I set the class in the Python scope -- still in C#:</div><div><br></div><div><div> ScreenTags SOA_screen = new ScreenTags();</div><div> scptScope.SetVariable("screen", SOA_screen);</div>
<div> scptSource = scptEngine.CreateScriptSourceFromFile(scriptFile); // scriptFile is Python code</div><div> scptSource.Execute(scptScope);</div><div><br></div><div>This is working fine. The class is actually really a loaded class, and it has all kind of goodies in it (ie pop up Windows forms, calls out to unmanaged code... all sorts of stuff). I never have a problem with any of it.</div>
<div><br></div><div>I don't know if this helps (or even if it is good practice!) but it is working here.</div></div></div><div><br></div><div><br></div></div>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>