[Python.NET] Is there a chance to imprive Python for .net to let "System.Windows.Forms.Form().Controls" be indexable?

Barton barton at BCDesignsWell.com
Sun Sep 4 08:39:45 CEST 2011


OK - I'll look into this further. It turns out the .NET 3.5 DOES allow this:

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Button btnCopy;
Button btn = new Button();
this.Controls.Add(btn);
btnCopy = (Button)this.Controls[0];
bool yes = (btn == btnCopy);
}
}
}

On 9/3/2011 8:31 PM, 刘振海 wrote:
> Hi Barton,
>
> **I don't think the Item Property isn't exposed due to its virtual
> nature. I did some test in C#,it turns out that the virtual modified
> Item property can be accessed by python .net with the index manner .I
> noticed there is a new function "get_Item" being add to the instance
> object. The same new function "get_Item" can be find in the
> Form().Controls but Form().Controls can not be indexable. It is wield.
> I check the source code of python for .net and find this from
> "classmanager.cs":
> // Check for indexer
> ParameterInfo[] args = pi.GetIndexParameters();
> if (args.GetLength(0) > 0) {
> Indexer idx = ci.indexer;
> if (idx == null) {
> ci.indexer = new Indexer();
> idx = ci.indexer;
> }
> idx.AddProperty(pi);
> continue;
> }
> Maybe the mechanism of checking for indexer is not perfect?
> Thanks!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20110903/914093da/attachment.html>


More information about the PythonDotNet mailing list