[Python.NET] Accessing class interface with private methods

Brian Lloyd brian.lloyd at revolutionhealth.com
Tue Dec 11 20:40:05 CET 2007


Better (or worse) yet, you can just use System.Reflection via python
to get at what you need ;)


On 12/11/07 2:23 PM, "Tijs Wickardt" <wickardt at xs4all.nl> wrote:

> Actually, there is a way to access private members in C#.
> You can use System.Reflection to modify access directives.
> 
> Since you can't access private members from Python .net, you could write a
> seperate C# module that unhides private members and exposes them as
> public.
> You could then call those public methods from Python for .NET.
> 
> Cumbersome, but should work.
> 
> Kind regards, Tijs
> 
> 
> 
> Feihong Hsu hsu.feihong at yahoo.com
> Sun Dec 9 15:54:23 CET 2007
> 
> Previous message: [Python.NET] Accessing class interface with private methods
> Next message: [Python.NET] Structure as argument
> Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> 
> ------------------------------------------------------------------------------
> --
> 
> 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
>         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

--------------------------
Brian Lloyd

brian.lloyd at revolutionhealth.com



More information about the PythonDotNet mailing list