views:

55

answers:

1

I have a .NET type 'MyClass' with a protected method that takes in an out parameter. For example:

protected bool MyMethod(out string value)

I am able to call this method on a 'MyClass' object created in Iron Python script. But however, the out variable 'value' is 'None' even if it is assigned some value in the method.

Now if I make it public, then all is fine.

Is this the expected behavior? Why does Iron Python allow protected methods to be called? Is it a conscious decision?

I am using Iron Python 2.0.1

+2  A: 

I believe this is intended behaviour, as MyMethod is effectively private to MyClass, so you are not supposed to be able to access it at all, not even on IronPython.

You can use reflection (InvokeMember) though to get arround this.


Looking around, it seems like this is indeed intended behaviour.

voyager
I am NOT suppose to be able to access it, BUT apparently I AM able to access it through IronPython. The question is whether this anomaly is the expected behaviour?
Poulo
@Poulo: I believe that you are able to see it, but unable to get any kind of value because of .Net's own architecture. You can merely see the structure, not the data. If you *need* to access it, may be to do some tests, you *can* use `InvokeMember`. Python only *hides* attributes that start `__`, the rest are supposed to be shown. I think that IronPython's implementation is doing the right thing. You might need to [ask to the developers](http://lists.ironpython.com/listinfo.cgi) to be sure. `None` is telling you that that name *exists* but has nothing set to it.
voyager