[Python.NET] Accessing class interface with private methods

lance23runner lance23runner at yahoo.com
Sat Dec 15 01:58:01 CET 2007


Cool.  Thanks Brian, this worked!

-Alex




Brian Lloyd-5 wrote:
> 
> have you tried explicitly calling this through the interface? You
> need to do something similar to a cast in C#:
>  
> from mynamespace import Foo, Iface
> 
> inst = Foo() # create an instance
> 
> wrapped = Iface(inst) # 'cast' to the interface
> 
> wrapped.Func() # should now work
> 
> hope this helps,
> 
> -Brian
> 
> 
> 
> On 12/9/07 4:01 PM, "lance23runner" <lance23runner at yahoo.com> wrote:
> 
>> 
>> I forgot to add "Implements Iface.Func" to method Func, I hope this
>> doesn't
>> confuse my problem.  It is added below.
>> 
>> The private method Func is accessible in VB.NET using the public IFACE.
>> This is intended so the class does not see these methods, but it can
>> access
>> them using the IFACE property.  A protected method doesn't provide the
>> abstraction.
>> 
>> Thanks,
>> -Alex
>> 
>> 
>> 
>> Feihong Hsu wrote:
>>> 
>>> This is not supported. You can't access private methods in C# or VB.NET
>>> either, so why should Python.NET be able to access them? But one thing
>>> to
>>> note is that you CAN access protected methods directly in Pyhon.NET (you
>>> don't have to make a subclass to use a protected method).
>>> 
>>> - Feihong
>>> 
>>> alex omoto <lance23runner at yahoo.com> wrote: Hi,
>>> 
>>> I am having trouble using Python.NET in accessing class interface
>>> methods
>>> that are declared private.  As an example,
>>> 
>>> Public Interface Iface
>>>     Property Func() As Boolean
>>> End Interface
>>> 
>>> Public Class Foo
>>>     Implements Iface
>>> 
>>>     Private Function Func() As Boolean Implements Iface.Func
>>>         Return True
>>>     End Function
>>> 
>>>     Public ReadOnly Property IFACE() As Iface
>>>         Get
>>>             Return Me
>>>         End Get
>>>     End Property
>>> End Class
>>> 
>>> Then using Python 2.5 with Python.Net 2.0 alpha 2,  I cannot access the
>>> method.  Is this supported?
>>> 
>>> import clr
>>> import Foo
>>> f =  Foo()
>>> f.IFACE              # OK
>>> f.IFACE.Func()    # results in Attribute error
>>> 
>>> 
>>> Thanks,
>>> Alex
> 
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
> 
> 

-- 
View this message in context: http://www.nabble.com/Accessing-class-interface-with-private-methods-tp14234892p14339876.html
Sent from the Python - pythondotnet mailing list archive at Nabble.com.



More information about the PythonDotNet mailing list