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

Very interesting;
Apparently, Microsoft doesn't think that it is a useful thing to
index directly into a System.Windows.Forms.Control.ControlCollection
Class.
The collection is still iterable in versions above 2.0, but the
class no longer supports indexing. So:

>>> print form.Controls[0] # works in pythondotnet
built on .NET 2.0 on prior.
<System.Windows.Forms.Button object at 0xaa8bc6c>
>>>

Very interesting;
Apparently, Microsoft doesn't think that it is a useful thing to
index directly into a
System.Windows.Forms.Control.ControlCollection Class.
The collection is still iterable in versions above 2.0, but the
class no longer supports indexing. So:

>>> print form.Controls[0] # works in
pythondotnet built on .NET 2.0 on prior.
<System.Windows.Forms.Button object at 0xaa8bc6c>
>>>

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

Yes, I agree that the Item Property is still there.
It seems to be exposed ONLY FROM IEnumerator.GetEnumerator() or the
Findxxx() functions provided by the class due to its virtual nature:

public virtual Control
this [ int index ] { get; }

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!

Hope that helps

On 9/3/2011 7:09 AM, 刘振海 wrote:

Hi Barton，

thanks for your reply.

I have check the MSDN documents. It seems the Item properties
both exist in .net2.0 and .net4.0

Very interesting;
Apparently, Microsoft doesn't think that it is a useful
thing to index directly into a
System.Windows.Forms.Control.ControlCollection Class.
The collection is still iterable in versions above 2.0,
but the class no longer supports indexing. So:

>>> print form.Controls[0] # works in
pythondotnet built on .NET 2.0 on prior.
<System.Windows.Forms.Button object at 0xaa8bc6c>
>>>

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":