.NET attributes for methods

View: New views
17 Messages — Rating Filter:   Alert me  

.NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython
via __clrtype__ metaclass
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He
describes how to add attributes to classes but not to methods. Is there
any example how to add attributes to a method. It looks like method
generation is necessary (like for getter and setter or in
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659)
but this is kind of deep magic for me...
Thanks.

--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Shri Borde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The following files extend DevHawk's blog and adds support for typed methods with attributes. It will be available as part of the samples released with the 2.6 RTM (over the next month). Do let us know if it works for you.

Also, I would be curious to know what scenario you need method attributes for (other than DllImport for pinvokes)...

-----Original Message-----
From: users-bounces@... [mailto:users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Thursday, October 22, 2009 10:37 AM
To: Discussion of IronPython
Subject: [IronPython] .NET attributes for methods

Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython
via __clrtype__ metaclass
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He
describes how to add attributes to classes but not to methods. Is there
any example how to add attributes to a method. It looks like method
generation is necessary (like for getter and setter or in
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659)
but this is kind of deep magic for me...
Thanks.

--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com




_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

clrtype.py (22K) Download Attachment
sample.py (7K) Download Attachment

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks.

I wanted to implement WCF service in pure Ironpython but I overlooked the [OperationContract] method attribute is used in the interface declaration. Anyway, thanks to class attributes it is now possible to implement the WCF service in IronPython and have only the interface done in C#. See my blog post:

http://gui-at.blogspot.com/2009/10/wcf-service-in-ironpython.html

DllImport is good to have too - I can get rid of of my Win32API.dll when simulating user's input :-)

--
-- Lukáš


Shri Borde wrote:
The following files extend DevHawk's blog and adds support for typed methods with attributes. It will be available as part of the samples released with the 2.6 RTM (over the next month). Do let us know if it works for you. 

Also, I would be curious to know what scenario you need method attributes for (other than DllImport for pinvokes)...

-----Original Message-----
From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Thursday, October 22, 2009 10:37 AM
To: Discussion of IronPython
Subject: [IronPython] .NET attributes for methods

Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython 
via __clrtype__ metaclass 
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He 
describes how to add attributes to classes but not to methods. Is there 
any example how to add attributes to a method. It looks like method 
generation is necessary (like for getter and setter or in 
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659) 
but this is kind of deep magic for me...
Thanks.

--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

  

_______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Shri Borde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

The clrtype module could be extended to make it possible to declare CLR interfaces in Python code. Something like:

 

class IFoo(object):

    __metaclass__ = ClrType.ClrInterface # Proposed way to indicate an interface

    @clrtype.accepts(int, str)

    @clrtype.returns(int)

    @clrtype.attribute(OperationContractAttribute)()

    def foo(i, s):raise RuntimeError("this should not get called")

 

This does not work today…

 

From: users-bounces@... [mailto:users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Friday, October 30, 2009 10:41 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks.

I wanted to implement WCF service in pure Ironpython but I overlooked the [OperationContract] method attribute is used in the interface declaration. Anyway, thanks to class attributes it is now possible to implement the WCF service in IronPython and have only the interface done in C#. See my blog post:

http://gui-at.blogspot.com/2009/10/wcf-service-in-ironpython.html

DllImport is good to have too - I can get rid of of my Win32API.dll when simulating user's input :-)

--
-- Lukáš


Shri Borde wrote:

The following files extend DevHawk's blog and adds support for typed methods with attributes. It will be available as part of the samples released with the 2.6 RTM (over the next month). Do let us know if it works for you. 
 
Also, I would be curious to know what scenario you need method attributes for (other than DllImport for pinvokes)...
 
-----Original Message-----
From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Thursday, October 22, 2009 10:37 AM
To: Discussion of IronPython
Subject: [IronPython] .NET attributes for methods
 
Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython 
via __clrtype__ metaclass 
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He 
describes how to add attributes to classes but not to methods. Is there 
any example how to add attributes to a method. It looks like method 
generation is necessary (like for getter and setter or in 
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659) 
but this is kind of deep magic for me...
Thanks.
 
--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
 
  
 


 
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
  

 


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I was thinking about this... Does ir mean that (after adding such support to clrtype) and building a .dll from the interface class, this class can be used from c#?

--
-- Lukáš


Shri Borde wrote:

The clrtype module could be extended to make it possible to declare CLR interfaces in Python code. Something like:

 

class IFoo(object):

    __metaclass__ = ClrType.ClrInterface # Proposed way to indicate an interface

    @clrtype.accepts(int, str)

    @clrtype.returns(int)

    @clrtype.attribute(OperationContractAttribute)()

    def foo(i, s):raise RuntimeError("this should not get called")

 

This does not work today…

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Friday, October 30, 2009 10:41 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks.

I wanted to implement WCF service in pure Ironpython but I overlooked the [OperationContract] method attribute is used in the interface declaration. Anyway, thanks to class attributes it is now possible to implement the WCF service in IronPython and have only the interface done in C#. See my blog post:

http://gui-at.blogspot.com/2009/10/wcf-service-in-ironpython.html

DllImport is good to have too - I can get rid of of my Win32API.dll when simulating user's input :-)

--
-- Lukáš


Shri Borde wrote:

The following files extend DevHawk's blog and adds support for typed methods with attributes. It will be available as part of the samples released with the 2.6 RTM (over the next month). Do let us know if it works for you. 
 
Also, I would be curious to know what scenario you need method attributes for (other than DllImport for pinvokes)...
 
-----Original Message-----
From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Thursday, October 22, 2009 10:37 AM
To: Discussion of IronPython
Subject: [IronPython] .NET attributes for methods
 
Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython 
via __clrtype__ metaclass 
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He 
describes how to add attributes to classes but not to methods. Is there 
any example how to add attributes to a method. It looks like method 
generation is necessary (like for getter and setter or in 
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659) 
but this is kind of deep magic for me...
Thanks.
 
--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
 
  
 

 
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
  

 


_______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Shri Borde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

It should be possible. However, note that you create the .dll using clr.GetSubclassedTypes (and clr.CompileSubclassedTypes) which requires you to run your application with all the scenarios you care about. You can’t just run a simple command line like “csc.exe foo.cs” and get a dll.

 

From: users-bounces@... [mailto:users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Monday, November 02, 2009 9:29 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I was thinking about this... Does ir mean that (after adding such support to clrtype) and building a .dll from the interface class, this class can be used from c#?

--
-- Lukáš


Shri Borde wrote:

The clrtype module could be extended to make it possible to declare CLR interfaces in Python code. Something like:

 

class IFoo(object):

    __metaclass__ = ClrType.ClrInterface # Proposed way to indicate an interface

    @clrtype.accepts(int, str)

    @clrtype.returns(int)

    @clrtype.attribute(OperationContractAttribute)()

    def foo(i, s):raise RuntimeError("this should not get called")

 

This does not work today…

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Friday, October 30, 2009 10:41 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks.

I wanted to implement WCF service in pure Ironpython but I overlooked the [OperationContract] method attribute is used in the interface declaration. Anyway, thanks to class attributes it is now possible to implement the WCF service in IronPython and have only the interface done in C#. See my blog post:

http://gui-at.blogspot.com/2009/10/wcf-service-in-ironpython.html

DllImport is good to have too - I can get rid of of my Win32API.dll when simulating user's input :-)

--
-- Lukáš


Shri Borde wrote:

The following files extend DevHawk's blog and adds support for typed methods with attributes. It will be available as part of the samples released with the 2.6 RTM (over the next month). Do let us know if it works for you. 
 
Also, I would be curious to know what scenario you need method attributes for (other than DllImport for pinvokes)...
 
-----Original Message-----
From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Thursday, October 22, 2009 10:37 AM
To: Discussion of IronPython
Subject: [IronPython] .NET attributes for methods
 
Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython 
via __clrtype__ metaclass 
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He 
describes how to add attributes to classes but not to methods. Is there 
any example how to add attributes to a method. It looks like method 
generation is necessary (like for getter and setter or in 
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659) 
but this is kind of deep magic for me...
Thanks.
 
--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
 
  
 
 


 
 
  
 
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
  

 

 


 
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
  

 


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

Shri Borde wrote:
The following files extend DevHawk's blog and adds support for typed methods with attributes. It will be available as part of the samples released with the 2.6 RTM (over the next month). Do let us know if it works for you. 

Also, I would be curious to know what scenario you need method attributes for (other than DllImport for pinvokes)...

-----Original Message-----
From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Thursday, October 22, 2009 10:37 AM
To: Discussion of IronPython
Subject: [IronPython] .NET attributes for methods

Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython 
via __clrtype__ metaclass 
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He 
describes how to add attributes to classes but not to methods. Is there 
any example how to add attributes to a method. It looks like method 
generation is necessary (like for getter and setter or in 
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659) 
but this is kind of deep magic for me...
Thanks.

--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

  

_______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Shri Borde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [mailto:users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

Shri Borde wrote:

The following files extend DevHawk's blog and adds support for typed methods with attributes. It will be available as part of the samples released with the 2.6 RTM (over the next month). Do let us know if it works for you. 
 
Also, I would be curious to know what scenario you need method attributes for (other than DllImport for pinvokes)...
 
-----Original Message-----
From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Thursday, October 22, 2009 10:37 AM
To: Discussion of IronPython
Subject: [IronPython] .NET attributes for methods
 
Hi,
I have read all DewHawk blogposts about .Net attributes in IronPython 
via __clrtype__ metaclass 
(http://devhawk.net/CategoryView,category,__clrtype__.aspx). He 
describes how to add attributes to classes but not to methods. Is there 
any example how to add attributes to a method. It looks like method 
generation is necessary (like for getter and setter or in 
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_10.shtml#e659) 
but this is kind of deep magic for me...
Thanks.
 
--
-- Lukáš
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
 
  
 


 
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
  

 


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I did change __metaclass__ to ClrMetaclass. See the attached source I use for testing - the only difference is to comment/uncomment appropriate part in product.py.

The outputs look the same, there are no visible exceptions:

DevHawk:
py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

Shri:
py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

--
-- Lukáš


Shri Borde wrote:

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip



_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

clrtypesltest.zip (8K) Download Attachment

Parent Message unknown Re: .NET attributes for methods

by Shri Borde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

So the new clrtype.py still works - cool!

 

I am not an expert on data binding, so I don’t have any suggestions. Why do you say that the decorator approach will not work with Silverlight? Does @notifiy_property from http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html use any feature not available in Silverlight?

 

From: Lukas Cenovsky [mailto:cenovsky@...]
Sent: Thursday, November 12, 2009 8:09 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks, that works!

What do you think would be the best approach to create notifiable properties for Silverlight? I did it for WPF (via decorators: http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html) but it seems to me it won't be possible to do it similarly for Silverlight...

--
-- Lukáš

Shri Borde wrote:

Can you use “_clrproperties” instead of “_clrfields”? DevHawk’s same created a field and a property even when you just used “_clrfields”. I don’t do that anymore. So you will need to use “_clrproperties” to get properties, which SL must use for data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Wednesday, November 11, 2009 2:37 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I did change __metaclass__ to ClrMetaclass. See the attached source I use for testing - the only difference is to comment/uncomment appropriate part in product.py.

The outputs look the same, there are no visible exceptions:

DevHawk:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))


Shri:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

 

--
-- Lukáš


Shri Borde wrote:

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

 


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Parent Message unknown Re: .NET attributes for methods

by Shri Borde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Here is an updated version of clrtype.py that uses @property + @clrtype.accepts/@... to indicate a CLR property, instead of using “_clrproperties”. I think its more Pythonic in general, but also you should be able to modify @notify_property to work with it.

 

Note that notify_property won’t just work. You will have to change it to propagate the func_name, arg_types, and return_type properties from the old getter/setter function objects to the new getter/setter function objects since these values are used by clrtype to generate the CLR members. Something like this:

 

class notify_property(property):

 

    def propagate_attributes(old_function, new_function):

        new_function.func_name = old_function.func_name

        new_function.arg_types = old_function.arg_types

        new_function.return_type = old_function.return_type

 

    def __init__(self, getter):

        def newgetter(slf):

            try:

                return getter(slf)

            except AttributeError:

                return None

        propagate_attributes(getter, newgetter)

        super(notify_property, self).__init__(newgetter)

 

    def setter(self, setter):

        def newsetter(slf, newvalue):

            oldvalue = self.fget(slf)

            if oldvalue != newvalue:

                setter(slf, newvalue)

                slf.OnPropertyChanged(setter.__name__)

        propagate_attributes(setter, newsetter)

        return property(

            fget=self.fget,

            fset=newsetter,

            fdel=self.fdel,

            doc=self.__doc__)

 

From: Lukas Cenovsky [mailto:cenovsky@...]
Sent: Thursday, November 12, 2009 11:01 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Shri Borde wrote:

So the new clrtype.py still works - cool!

Yep ;-)

 I am not an expert on data binding, so I don’t have any suggestions. Why do you say that the decorator approach will not work with Silverlight? Does @notifiy_property from http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html use any feature not available in Silverlight?

It does not (as far as I know because it is pure IronPython). But @notify_property does not work with clrtypes:

class ViewModel(NotifyPropertyChangedBase):
    __metaclass__ = clrtype.ClrMetaclass
    _clrnamespace = "Cenda.ViewModel"
    _clrproperties = {'size': str}
    
    def __init__(self):
        super(ViewModel, self).__init__()
        # must be string to two-way binding work correctly
        self.size = '10'
 
    @notify_property
    def size(self):
        return self._size
 
    @size.setter
    def size(self, value):
        self._size = value
        print 'Size changed to %r' % self.size
 


When I run this code, the size is still clr property and Python getter and setter are not run.

So basically I need to override/enhance clr getter and setter created by clrtype._clrproperties.

--
-- Lukáš


 

From: Lukas Cenovsky [cenovsky@...]
Sent: Thursday, November 12, 2009 8:09 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks, that works!

What do you think would be the best approach to create notifiable properties for Silverlight? I did it for WPF (via decorators: http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html) but it seems to me it won't be possible to do it similarly for Silverlight...

--
-- Lukáš

Shri Borde wrote:

Can you use “_clrproperties” instead of “_clrfields”? DevHawk’s same created a field and a property even when you just used “_clrfields”. I don’t do that anymore. So you will need to use “_clrproperties” to get properties, which SL must use for data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Wednesday, November 11, 2009 2:37 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I did change __metaclass__ to ClrMetaclass. See the attached source I use for testing - the only difference is to comment/uncomment appropriate part in product.py.

The outputs look the same, there are no visible exceptions:

DevHawk:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))


Shri:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

 

--
-- Lukáš


Shri Borde wrote:

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

 

 




_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

clrtype.py (29K) Download Attachment
sample.py (9K) Download Attachment

Re: .NET attributes for methods

by Curt Hagenlocher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Silverlight doesn't support ICustomTypeDescriptor -- that's probably why binding is failing. You need to emit CLR properties to use data binding with Silverlight 2 and 3.

2009/11/12 Shri Borde <Shri.Borde@...>

So the new clrtype.py still works - cool!

 

I am not an expert on data binding, so I don’t have any suggestions. Why do you say that the decorator approach will not work with Silverlight? Does @notifiy_property from http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html use any feature not available in Silverlight?

 

From: Lukas Cenovsky [mailto:cenovsky@...]
Sent: Thursday, November 12, 2009 8:09 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks, that works!

What do you think would be the best approach to create notifiable properties for Silverlight? I did it for WPF (via decorators: http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html) but it seems to me it won't be possible to do it similarly for Silverlight...

--
-- Lukáš

Shri Borde wrote:

Can you use “_clrproperties” instead of “_clrfields”? DevHawk’s same created a field and a property even when you just used “_clrfields”. I don’t do that anymore. So you will need to use “_clrproperties” to get properties, which SL must use for data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Wednesday, November 11, 2009 2:37 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I did change __metaclass__ to ClrMetaclass. See the attached source I use for testing - the only difference is to comment/uncomment appropriate part in product.py.

The outputs look the same, there are no visible exceptions:

DevHawk:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))


Shri:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

 

--
-- Lukáš


Shri Borde wrote:

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

 


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
This looks very promising but I cannot make it work. I have changed product.py in DevHawk's example to:

#from clrtypeold import ClrMetaclass
import clrtype

class Product(object):
  #__metaclass__ = ClrMetaclass
  __metaclass__ = clrtype.ClrClass
  _clrnamespace = "DevHawk.IronPython.ClrTypeSeries"
  #_clrproperties = {
    #"name":str,
    #"cost":float,
    #"quantity":int,
    #}
    
  def __init__(self, name, cost, quantity):
    self.name = name
    self.cost = cost
    self.quantity = quantity
    
  def calc_total(self):
    return self.cost * self.quantity

  @property
  @clrtype.accepts()
  @clrtype.returns(str)
  def name(self):
      return self._name

  @name.setter
  @clrtype.accepts(str)
  @clrtype.returns()
  def name(self, value):
      self._name = value

When I run it I don't see any items in the listbox. When I check the name, it is a property:

py> a.root.listbox1.Items[0]
=> <Product object at 0x000000000000002B>
py> a.root.listbox1.Items[0].GetType().GetProperties()
=> Array[PropertyInfo]((<System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]>))

Whe I used the old clrtype with _clrproperties = {'name': str, ...}, it
worked.

--
-- Lukáš


Shri Borde wrote:

Here is an updated version of clrtype.py that uses @property + @clrtype.accepts/@... to indicate a CLR property, instead of using “_clrproperties”. I think its more Pythonic in general, but also you should be able to modify @notify_property to work with it.

 

Note that notify_property won’t just work. You will have to change it to propagate the func_name, arg_types, and return_type properties from the old getter/setter function objects to the new getter/setter function objects since these values are used by clrtype to generate the CLR members. Something like this:

 

class notify_property(property):

 

    def propagate_attributes(old_function, new_function):

        new_function.func_name = old_function.func_name

        new_function.arg_types = old_function.arg_types

        new_function.return_type = old_function.return_type

 

    def __init__(self, getter):

        def newgetter(slf):

            try:

                return getter(slf)

            except AttributeError:

                return None

        propagate_attributes(getter, newgetter)

        super(notify_property, self).__init__(newgetter)

 

    def setter(self, setter):

        def newsetter(slf, newvalue):

            oldvalue = self.fget(slf)

            if oldvalue != newvalue:

                setter(slf, newvalue)

                slf.OnPropertyChanged(setter.__name__)

        propagate_attributes(setter, newsetter)

        return property(

            fget=self.fget,

            fset=newsetter,

            fdel=self.fdel,

            doc=self.__doc__)

 

From: Lukas Cenovsky [cenovsky@...]
Sent: Thursday, November 12, 2009 11:01 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Shri Borde wrote:

So the new clrtype.py still works - cool!

Yep ;-)

 I am not an expert on data binding, so I don’t have any suggestions. Why do you say that the decorator approach will not work with Silverlight? Does @notifiy_property from http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html use any feature not available in Silverlight?

It does not (as far as I know because it is pure IronPython). But @notify_property does not work with clrtypes:

class ViewModel(NotifyPropertyChangedBase):
    __metaclass__ = clrtype.ClrMetaclass
    _clrnamespace = "Cenda.ViewModel"
    _clrproperties = {'size': str}
    
    def __init__(self):
        super(ViewModel, self).__init__()
        # must be string to two-way binding work correctly
        self.size = '10'
 
    @notify_property
    def size(self):
        return self._size
 
    @size.setter
    def size(self, value):
        self._size = value
        print 'Size changed to %r' % self.size
 


When I run this code, the size is still clr property and Python getter and setter are not run.

So basically I need to override/enhance clr getter and setter created by clrtype._clrproperties.

--
-- Lukáš


 

From: Lukas Cenovsky [cenovsky@...]
Sent: Thursday, November 12, 2009 8:09 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks, that works!

What do you think would be the best approach to create notifiable properties for Silverlight? I did it for WPF (via decorators: http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html) but it seems to me it won't be possible to do it similarly for Silverlight...

--
-- Lukáš

Shri Borde wrote:

Can you use “_clrproperties” instead of “_clrfields”? DevHawk’s same created a field and a property even when you just used “_clrfields”. I don’t do that anymore. So you will need to use “_clrproperties” to get properties, which SL must use for data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Wednesday, November 11, 2009 2:37 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I did change __metaclass__ to ClrMetaclass. See the attached source I use for testing - the only difference is to comment/uncomment appropriate part in product.py.

The outputs look the same, there are no visible exceptions:

DevHawk:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))


Shri:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

 

--
-- Lukáš


Shri Borde wrote:

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

 

 


_______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I also tested creating interfaces and it fails with the exception below. Does this mean it will not be possible to use IronPython interface in Silverlight because of AppDomain?

--
-- Lukáš

SystemError: Application code cannot access System.AppDomain.get_CurrentDomain() using Reflection.

clrtype.py
Line 180:             validate_clr_types(b)
Line 181:         if not ClrInterface.interface_module_builder:
Line 182:             assembly_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(AssemblyName("interfaces"), AssemblyBuilderAccess.Run)
Line 183:             ClrInterface.interface_module_builder = assembly_builder.DefineDynamicModule("interfaces")
Line 184:         attrs = TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract

SystemError
at define_interface in clrtype.py, line 182
at __clrtype__ in clrtype.py, line 213
at app.py in app.py, line 12
CLR Stack Trace:
   at System.Reflection.MethodBase.PerformSecurityCheck(Object obj, RuntimeMethodHandle method, IntPtr parent, UInt32 invocationFlags)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)
   at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`1.Call0(CallSite site, CodeContext context, TFuncType func)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at IronPython.Runtime.Types.BuiltinFunction.Call0(CodeContext context, SiteLocalStorage`1 storage, Object instance)
   at IronPython.Runtime.Types.ReflectedProperty.CallGetter(CodeContext context, PythonType owner, SiteLocalStorage`1 storage, Object instance)
   at IronPython.Runtime.Types.ReflectedProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
   at IronPython.Runtime.Binding.MetaPythonType.FastGetBinderHelper.SlotAccessDelegate.Target(CodeContext context, Object self, Object& result)
   at IronPython.Runtime.Types.TypeGetBase.RunDelegatesNoOptimize(Object self, CodeContext context)
   at IronPython.Runtime.Types.SystemTypeGet.Target(CallSite site, Object self, CodeContext context)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at clrtype$3.define_interface$21(PythonFunction $function, Object typename, Object bases)
   at IronPython.Runtime.PythonFunction.FunctionCaller`2.Call2(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at clrtype$3.__clrtype__$23(PythonFunction $function, Object self)
   at IronPython.Runtime.PythonFunction.FunctionCaller`1.Call1(CallSite site, CodeContext context, Object func, T0 arg0)
   at CallSite.Target(Closure , CallSite , CodeContext , Object )
   at IronPython.NewTypes.IronPython.Runtime.Types.PythonType_1$1.__clrtype__()
   at IronPython.Runtime.Types.PythonType.InitializeUserType(CodeContext context, String name, PythonTuple bases, PythonDictionary vars)
   at IronPython.Runtime.Types.PythonType..ctor(CodeContext context, String name, PythonTuple bases, PythonDictionary dict)
   at IronPython.NewTypes.IronPython.Runtime.Types.PythonType_1$1..ctor(CodeContext context, PythonType cls, String name, PythonTuple bases, PythonDictionary dict)
   at CallSite.Target(Closure , CallSite , CodeContext , BuiltinFunction , PythonType , Object , Object , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at IronPython.Runtime.Types.UserInstanceCreator.CreateInstance(CodeContext context, Object arg0, Object arg1, Object arg2)
   at IronPython.Runtime.Types.PythonType.CreateInstance(CodeContext context, Object arg0, Object arg1, Object arg2)
   at IronPython.Runtime.Types.PythonType.__new__(CodeContext context, PythonType cls, String name, PythonTuple bases, PythonDictionary dict)
   at CallSite.Target(Closure , CallSite , CodeContext , Object , String , PythonTuple , PythonDictionary )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
   at CallSite.Target(Closure , CallSite , CodeContext , Object , String , PythonTuple , PythonDictionary )
   at IronPython.Runtime.Operations.PythonOps.MakeClass(CodeContext context, String name, Object[] bases, String selfNames, PythonDictionary vars)
   at IronPython.Runtime.Operations.PythonOps.MakeClass(Object body, CodeContext parentContext, String name, Object[] bases, String selfNames)
   at <unnamed>$1.<unnamed>(CodeContext $globalContext, FunctionCode functionCode)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.Hosting.CompiledCode.Execute(ScriptScope scope)
   at Microsoft.Scripting.Silverlight.DynamicEngine.Run(String entryPoint)
   at Microsoft.Scripting.Silverlight.DynamicApplication.<DynamicApplication_Startup>b__1()
   at Microsoft.Scripting.Silverlight.Cache.Download(List`1 uris, Action onComplete)
   at Microsoft.Scripting.Silverlight.HttpVirtualFilesystem.DownloadAndCache(List`1 uris, Action onComplete)
   at Microsoft.Scripting.Silverlight.DynamicScriptTags.DownloadExternalCode(Action onComplete)
   at Microsoft.Scripting.Silverlight.DynamicApplication.<DynamicApplication_Startup>b__0()
   at Microsoft.Scripting.Silverlight.DynamicLanguageConfig.DownloadLanguages(DynamicAppManifest appManifest, Action onComplete)
   at Microsoft.Scripting.Silverlight.DynamicApplication.DynamicApplication_Startup(Object sender, StartupEventArgs e)
   at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)


Shri Borde wrote:

Here is an updated version of clrtype.py that uses @property + @clrtype.accepts/@... to indicate a CLR property, instead of using “_clrproperties”. I think its more Pythonic in general, but also you should be able to modify @notify_property to work with it.

 

Note that notify_property won’t just work. You will have to change it to propagate the func_name, arg_types, and return_type properties from the old getter/setter function objects to the new getter/setter function objects since these values are used by clrtype to generate the CLR members. Something like this:

 

class notify_property(property):

 

    def propagate_attributes(old_function, new_function):

        new_function.func_name = old_function.func_name

        new_function.arg_types = old_function.arg_types

        new_function.return_type = old_function.return_type

 

    def __init__(self, getter):

        def newgetter(slf):

            try:

                return getter(slf)

            except AttributeError:

                return None

        propagate_attributes(getter, newgetter)

        super(notify_property, self).__init__(newgetter)

 

    def setter(self, setter):

        def newsetter(slf, newvalue):

            oldvalue = self.fget(slf)

            if oldvalue != newvalue:

                setter(slf, newvalue)

                slf.OnPropertyChanged(setter.__name__)

        propagate_attributes(setter, newsetter)

        return property(

            fget=self.fget,

            fset=newsetter,

            fdel=self.fdel,

            doc=self.__doc__)

 

From: Lukas Cenovsky [cenovsky@...]
Sent: Thursday, November 12, 2009 11:01 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Shri Borde wrote:

So the new clrtype.py still works - cool!

Yep ;-)

 I am not an expert on data binding, so I don’t have any suggestions. Why do you say that the decorator approach will not work with Silverlight? Does @notifiy_property from http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html use any feature not available in Silverlight?

It does not (as far as I know because it is pure IronPython). But @notify_property does not work with clrtypes:

class ViewModel(NotifyPropertyChangedBase):
    __metaclass__ = clrtype.ClrMetaclass
    _clrnamespace = "Cenda.ViewModel"
    _clrproperties = {'size': str}
    
    def __init__(self):
        super(ViewModel, self).__init__()
        # must be string to two-way binding work correctly
        self.size = '10'
 
    @notify_property
    def size(self):
        return self._size
 
    @size.setter
    def size(self, value):
        self._size = value
        print 'Size changed to %r' % self.size
 


When I run this code, the size is still clr property and Python getter and setter are not run.

So basically I need to override/enhance clr getter and setter created by clrtype._clrproperties.

--
-- Lukáš


 

From: Lukas Cenovsky [cenovsky@...]
Sent: Thursday, November 12, 2009 8:09 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks, that works!

What do you think would be the best approach to create notifiable properties for Silverlight? I did it for WPF (via decorators: http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html) but it seems to me it won't be possible to do it similarly for Silverlight...

--
-- Lukáš

Shri Borde wrote:

Can you use “_clrproperties” instead of “_clrfields”? DevHawk’s same created a field and a property even when you just used “_clrfields”. I don’t do that anymore. So you will need to use “_clrproperties” to get properties, which SL must use for data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Wednesday, November 11, 2009 2:37 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I did change __metaclass__ to ClrMetaclass. See the attached source I use for testing - the only difference is to comment/uncomment appropriate part in product.py.

The outputs look the same, there are no visible exceptions:

DevHawk:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))


Shri:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

 

--
-- Lukáš


Shri Borde wrote:

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

 

 


_______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Shri Borde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I can help you create a property. And I can help you get it to work with your decorators (you can check if the “name” property exposes your @notify_property wrapper methods or not, and presumably that works). Beyond that, you are on your own :)

 

I would try calling the property methods to make sure they are accessible. Something like this. If that works, I am not sure what Silverlight needs to make databinding happy.

 

props = a.root.listbox1.Items[0].GetType().GetProperties()

prop = props[0]

prop.GetGetMethod.Invoke(a, None) # call using Reflection

 

About the “SystemError: Application code cannot access System.AppDomain.get_CurrentDomain() using Reflection.” error when defining interfaces, it could be worked around. We need to call AppDomain.DefineDynamicAssembly, and IronPython itself does do this. So its just a question of figuring out the right way to access an AppDomain instance. Will look into it, but I doubt it will help you with data binding.

 

From: users-bounces@... [mailto:users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Friday, November 13, 2009 5:42 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

This looks very promising but I cannot make it work. I have changed product.py in DevHawk's example to:

#from clrtypeold import ClrMetaclass
import clrtype
 
class Product(object):
  #__metaclass__ = ClrMetaclass
  __metaclass__ = clrtype.ClrClass
  _clrnamespace = "DevHawk.IronPython.ClrTypeSeries"
  #_clrproperties = {
    #"name":str,
    #"cost":float,
    #"quantity":int,
    #}
    
  def __init__(self, name, cost, quantity):
    self.name = name
    self.cost = cost
    self.quantity = quantity
    
  def calc_total(self):
    return self.cost * self.quantity
 
  @property
  @clrtype.accepts()
  @clrtype.returns(str)
  def name(self):
      return self._name
 
  @name.setter
  @clrtype.accepts(str)
  @clrtype.returns()
  def name(self, value):
      self._name = value
 

When I run it I don't see any items in the listbox. When I check the name, it is a property:

py> a.root.listbox1.Items[0]
=> <Product object at 0x000000000000002B>
py> a.root.listbox1.Items[0].GetType().GetProperties()
=> Array[PropertyInfo]((<System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]>))
 

Whe I used the old clrtype with _clrproperties = {'name': str, ...}, it worked.

--
-- Lukáš


Shri Borde wrote:

Here is an updated version of clrtype.py that uses @property + @clrtype.accepts/@... to indicate a CLR property, instead of using “_clrproperties”. I think its more Pythonic in general, but also you should be able to modify @notify_property to work with it.

 

Note that notify_property won’t just work. You will have to change it to propagate the func_name, arg_types, and return_type properties from the old getter/setter function objects to the new getter/setter function objects since these values are used by clrtype to generate the CLR members. Something like this:

 

class notify_property(property):

 

    def propagate_attributes(old_function, new_function):

        new_function.func_name = old_function.func_name

        new_function.arg_types = old_function.arg_types

        new_function.return_type = old_function.return_type

 

    def __init__(self, getter):

        def newgetter(slf):

            try:

                return getter(slf)

            except AttributeError:

                return None

        propagate_attributes(getter, newgetter)

        super(notify_property, self).__init__(newgetter)

 

    def setter(self, setter):

        def newsetter(slf, newvalue):

            oldvalue = self.fget(slf)

            if oldvalue != newvalue:

                setter(slf, newvalue)

                slf.OnPropertyChanged(setter.__name__)

        propagate_attributes(setter, newsetter)

        return property(

            fget=self.fget,

            fset=newsetter,

            fdel=self.fdel,

            doc=self.__doc__)

 

From: Lukas Cenovsky [cenovsky@...]
Sent: Thursday, November 12, 2009 11:01 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Shri Borde wrote:

So the new clrtype.py still works - cool!

Yep ;-)


 I am not an expert on data binding, so I don’t have any suggestions. Why do you say that the decorator approach will not work with Silverlight? Does @notifiy_property from http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html use any feature not available in Silverlight?

It does not (as far as I know because it is pure IronPython). But @notify_property does not work with clrtypes:

class ViewModel(NotifyPropertyChangedBase):
    __metaclass__ = clrtype.ClrMetaclass
    _clrnamespace = "Cenda.ViewModel"
    _clrproperties = {'size': str}
    
    def __init__(self):
        super(ViewModel, self).__init__()
        # must be string to two-way binding work correctly
        self.size = '10'
 
    @notify_property
    def size(self):
        return self._size
 
    @size.setter
    def size(self, value):
        self._size = value
        print 'Size changed to %r' % self.size
 


When I run this code, the size is still clr property and Python getter and setter are not run.

So basically I need to override/enhance clr getter and setter created by clrtype._clrproperties.

--
-- Lukáš



 

From: Lukas Cenovsky [cenovsky@...]
Sent: Thursday, November 12, 2009 8:09 AM
To: Shri Borde
Subject: Re: [IronPython] .NET attributes for methods

 

Thanks, that works!

What do you think would be the best approach to create notifiable properties for Silverlight? I did it for WPF (via decorators: http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html) but it seems to me it won't be possible to do it similarly for Silverlight...

--
-- Lukáš

Shri Borde wrote:

Can you use “_clrproperties” instead of “_clrfields”? DevHawk’s same created a field and a property even when you just used “_clrfields”. I don’t do that anymore. So you will need to use “_clrproperties” to get properties, which SL must use for data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Wednesday, November 11, 2009 2:37 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I did change __metaclass__ to ClrMetaclass. See the attached source I use for testing - the only difference is to comment/uncomment appropriate part in product.py.

The outputs look the same, there are no visible exceptions:

DevHawk:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))


Shri:

py> a.root.FindName('listbox1').ItemsSource[0].GetType().GetFields()
=> Array[FieldInfo]((<System.Reflection.RtFieldInfo object at 0x000000000000002B [Double cost]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002C [Int32 quantity]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002D [System.String name]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002E [IronPython.Runtime.Types.PythonType .class]>,
<System.Reflection.RtFieldInfo object at 0x000000000000002F [IronPython.Runtime.PythonDictionary .dict]>,
<System.Reflection.RtFieldInfo object at 0x0000000000000030 [System.Object[] .slots_and_weakref]>))

 

--
-- Lukáš


Shri Borde wrote:

Note that you will have to set __metaclass__ to ClrMetaclass, not ClrTypeMetaclass as in DevHawk’s sample. I had changed the name of the type. The old name will cause a NameError, but maybe SL is hiding exceptions. Can you do “o.GetType().GetFields()” and display that on the page to inspect the object and also make sure that no exceptions were thrown?

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Tuesday, November 10, 2009 2:59 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

I have just found that the Silverlight binding does not work with this version of clrtype and/or IronPython 2.6RC2.
I used DevHawk demo [1] and after I added reference to Microsoft.Dynamic in clrtypemetaclass.py it worked flawlessly. But when I switch to your version, no items show in the listbox.

By the way - I have seen a commit message you have added support for interfaces - nice! ;-)

--
-- Lukáš

[1] http://cid-0d9bc809858885a4.skydrive.live.com/self.aspx/DevHawk%20Content/IronPython%20Stuff/^_^_clrtype^_^_/SL%20databinding%20demo.zip

 

 

 


 
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
  

 


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Help with getting properties to work will hopefully resolve the databinding as well ;-)

The property getter looks wrong but I have no idea what's wrong:

py> props = a.root.listbox1.Items[0].GetType().GetProperties()
py> props
=> Array[PropertyInfo]((<System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]>))
py> prop = props[0]
py> prop.GetGetMethod()
=> <System.Reflection.RuntimeMethodInfo object at 0x000000000000002B [System.String name()]>
py> prop.GetGetMethod().Invoke(a.root.listbox1.Items[0], None)
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
  at <module> in <string>, line 0

Just for clarification "a" is Silverlight Application instance

As for the interface error - this is a different strory. You may remember I created WCF service in IronPython with just interface defined in C#. To be able to move interface to IronPython, I need such interface to work with Silverlight too because Silverlight is the cause why I am building WCF services.

--
-- Lukáš


Shri Borde wrote:

I can help you create a property. And I can help you get it to work with your decorators (you can check if the “name” property exposes your @notify_property wrapper methods or not, and presumably that works). Beyond that, you are on your own :)

 

I would try calling the property methods to make sure they are accessible. Something like this. If that works, I am not sure what Silverlight needs to make databinding happy.

 

props = a.root.listbox1.Items[0].GetType().GetProperties()

prop = props[0]

prop.GetGetMethod.Invoke(a, None) # call using Reflection

 

About the “SystemError: Application code cannot access System.AppDomain.get_CurrentDomain() using Reflection.” error when defining interfaces, it could be worked around. We need to call AppDomain.DefineDynamicAssembly, and IronPython itself does do this. So its just a question of figuring out the right way to access an AppDomain instance. Will look into it, but I doubt it will help you with data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Friday, November 13, 2009 5:42 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

This looks very promising but I cannot make it work. I have changed product.py in DevHawk's example to:

#from clrtypeold import ClrMetaclass
import clrtype
 
class Product(object):
  #__metaclass__ = ClrMetaclass
  __metaclass__ = clrtype.ClrClass
  _clrnamespace = "DevHawk.IronPython.ClrTypeSeries"
  #_clrproperties = {
    #"name":str,
    #"cost":float,
    #"quantity":int,
    #}
    
  def __init__(self, name, cost, quantity):
    self.name = name
    self.cost = cost
    self.quantity = quantity
    
  def calc_total(self):
    return self.cost * self.quantity
 
  @property
  @clrtype.accepts()
  @clrtype.returns(str)
  def name(self):
      return self._name
 
  @name.setter
  @clrtype.accepts(str)
  @clrtype.returns()
  def name(self, value):
      self._name = value
 

When I run it I don't see any items in the listbox. When I check the name, it is a property:

py> a.root.listbox1.Items[0]
=> <Product object at 0x000000000000002B>
py> a.root.listbox1.Items[0].GetType().GetProperties()
=> Array[PropertyInfo]((<System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]>))
 

Whe I used the old clrtype with _clrproperties = {'name': str, ...}, it worked.

--
-- Lukáš


Shri Borde wrote:

Here is an updated version of clrtype.py that uses @property + @clrtype.accepts/@... to indicate a CLR property, instead of using “_clrproperties”. I think its more Pythonic in general, but also you should be able to modify @notify_property to work with it.

 

Note that notify_property won’t just work. You will have to change it to propagate the func_name, arg_types, and return_type properties from the old getter/setter function objects to the new getter/setter function objects since these values are used by clrtype to generate the CLR members. Something like this:

 

class notify_property(property):

 

    def propagate_attributes(old_function, new_function):

        new_function.func_name = old_function.func_name

        new_function.arg_types = old_function.arg_types

        new_function.return_type = old_function.return_type

 

    def __init__(self, getter):

        def newgetter(slf):

            try:

                return getter(slf)

            except AttributeError:

                return None

        propagate_attributes(getter, newgetter)

        super(notify_property, self).__init__(newgetter)

 

    def setter(self, setter):

        def newsetter(slf, newvalue):

            oldvalue = self.fget(slf)

            if oldvalue != newvalue:

                setter(slf, newvalue)

                slf.OnPropertyChanged(setter.__name__)

        propagate_attributes(setter, newsetter)

        return property(

            fget=self.fget,

            fset=newsetter,

            fdel=self.fdel,

            doc=self.__doc__)


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: .NET attributes for methods

by Lukas Cenovsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Thanks to Shri and the new clrtype both issues are resolved. I will post details soon on my blog.

--
-- Lukáš

Lukas Cenovsky wrote:
Help with getting properties to work will hopefully resolve the databinding as well ;-)

The property getter looks wrong but I have no idea what's wrong:

py> props = a.root.listbox1.Items[0].GetType().GetProperties()
py> props
=> Array[PropertyInfo]((<System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]>))
py> prop = props[0]
py> prop.GetGetMethod()
=> <System.Reflection.RuntimeMethodInfo object at 0x000000000000002B [System.String name()]>
py> prop.GetGetMethod().Invoke(a.root.listbox1.Items[0], None)
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
  at <module> in <string>, line 0
  

Just for clarification "a" is Silverlight Application instance

As for the interface error - this is a different strory. You may remember I created WCF service in IronPython with just interface defined in C#. To be able to move interface to IronPython, I need such interface to work with Silverlight too because Silverlight is the cause why I am building WCF services.

--
-- Lukáš


Shri Borde wrote:

I can help you create a property. And I can help you get it to work with your decorators (you can check if the “name” property exposes your @notify_property wrapper methods or not, and presumably that works). Beyond that, you are on your own :)

 

I would try calling the property methods to make sure they are accessible. Something like this. If that works, I am not sure what Silverlight needs to make databinding happy.

 

props = a.root.listbox1.Items[0].GetType().GetProperties()

prop = props[0]

prop.GetGetMethod.Invoke(a, None) # call using Reflection

 

About the “SystemError: Application code cannot access System.AppDomain.get_CurrentDomain() using Reflection.” error when defining interfaces, it could be worked around. We need to call AppDomain.DefineDynamicAssembly, and IronPython itself does do this. So its just a question of figuring out the right way to access an AppDomain instance. Will look into it, but I doubt it will help you with data binding.

 

From: users-bounces@... [users-bounces@...] On Behalf Of Lukas Cenovsky
Sent: Friday, November 13, 2009 5:42 AM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET attributes for methods

 

This looks very promising but I cannot make it work. I have changed product.py in DevHawk's example to:

#from clrtypeold import ClrMetaclass
import clrtype
 
class Product(object):
  #__metaclass__ = ClrMetaclass
  __metaclass__ = clrtype.ClrClass
  _clrnamespace = "DevHawk.IronPython.ClrTypeSeries"
  #_clrproperties = {
    #"name":str,
    #"cost":float,
    #"quantity":int,
    #}
    
  def __init__(self, name, cost, quantity):
    self.name = name
    self.cost = cost
    self.quantity = quantity
    
  def calc_total(self):
    return self.cost * self.quantity
 
  @property
  @clrtype.accepts()
  @clrtype.returns(str)
  def name(self):
      return self._name
 
  @name.setter
  @clrtype.accepts(str)
  @clrtype.returns()
  def name(self, value):
      self._name = value
 

When I run it I don't see any items in the listbox. When I check the name, it is a property:

py> a.root.listbox1.Items[0]
=> <Product object at 0x000000000000002B>
py> a.root.listbox1.Items[0].GetType().GetProperties()
=> Array[PropertyInfo]((<System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]>))
 

Whe I used the old clrtype with _clrproperties = {'name': str, ...}, it worked.

--
-- Lukáš


Shri Borde wrote:

Here is an updated version of clrtype.py that uses @property + @clrtype.accepts/@... to indicate a CLR property, instead of using “_clrproperties”. I think its more Pythonic in general, but also you should be able to modify @notify_property to work with it.

 

Note that notify_property won’t just work. You will have to change it to propagate the func_name, arg_types, and return_type properties from the old getter/setter function objects to the new getter/setter function objects since these values are used by clrtype to generate the CLR members. Something like this:

 

class notify_property(property):

 

    def propagate_attributes(old_function, new_function):

        new_function.func_name = old_function.func_name

        new_function.arg_types = old_function.arg_types

        new_function.return_type = old_function.return_type

 

    def __init__(self, getter):

        def newgetter(slf):

            try:

                return getter(slf)

            except AttributeError:

                return None

        propagate_attributes(getter, newgetter)

        super(notify_property, self).__init__(newgetter)

 

    def setter(self, setter):

        def newsetter(slf, newvalue):

            oldvalue = self.fget(slf)

            if oldvalue != newvalue:

                setter(slf, newvalue)

                slf.OnPropertyChanged(setter.__name__)

        propagate_attributes(setter, newsetter)

        return property(

            fget=self.fget,

            fset=newsetter,

            fdel=self.fdel,

            doc=self.__doc__)


_______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com