<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks to Shri and the new clrtype both issues are resolved. I will
post details soon on my blog.<br>
<br>
--<br>
-- Luká¹<br>
<br>
Lukas Cenovsky wrote:
<blockquote cite="mid:4AFD88A1.30807@bakalari.cz" type="cite">
  <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
Help with getting properties to work will hopefully resolve the
databinding as well ;-)<br>
  <br>
The property getter looks wrong but I have no idea what's wrong:<br>
  <br>
  <pre><span class="silverlightDlrReplPrompt">py&gt; </span>props = a.root.listbox1.Items[0].GetType().GetProperties()
py&gt; props
=&gt; Array[PropertyInfo]((&lt;System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]&gt;))
py&gt; <span class="silverlightDlrReplPrompt"></span>prop = props[0]
py&gt; prop.GetGetMethod()
=&gt; &lt;System.Reflection.RuntimeMethodInfo object at 0x000000000000002B [System.String name()]&gt;
py&gt; prop.GetGetMethod().Invoke(a.root.listbox1.Items[0], None)
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
  at &lt;module&gt; in &lt;string&gt;, line 0
  </pre>
  <span class="silverlightDlrReplOutput"></span><br>
Just for clarification "<tt>a"</tt> is Silverlight Application instance<br>
  <br>
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.<br>
  <br>
--<br>
-- Luká¹<br>
  <br>
  <br>
Shri Borde wrote:
  <blockquote
 cite="mid:8E45365BECA665489F3CB8878A6C1B7D0C800CB2@TK5EX14MBXC140.redmond.corp.microsoft.com"
 type="cite">
    <meta http-equiv="Content-Type" content="text/html; ">
    <meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
    <style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.silverlightdlrreplprompt
        {mso-style-name:silverlightdlrreplprompt;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle23
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle24
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
  </style><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
    <div class="Section1">
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">I
can help you create a property. And I can help you get it to
work with your decorators (you can check if the &#8220;name&#8221; property
exposes your @notify_property wrapper methods or not, and presumably
that works).
Beyond that, you are on your own :) <o:p></o:p></span></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">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.<o:p></o:p></span></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
    <p class="MsoNormal">props =
a.root.listbox1.Items[0].GetType().GetProperties()<o:p></o:p></p>
    <p class="MsoNormal">prop = props[0]<o:p></o:p></p>
    <p class="MsoNormal">prop.GetGetMethod.Invoke(a, None) # call using
Reflection<span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p></o:p></span></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">About
the &#8220;SystemError: Application code cannot access
System.AppDomain.get_CurrentDomain() using Reflection.&#8221; 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.<o:p></o:p></span></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
    <div>
    <div
 style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">
    <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Tahoma&quot;,&quot;sans-serif&quot;; color: windowtext;">From:</span></b><span
 style="font-size: 10pt; font-family: &quot;Tahoma&quot;,&quot;sans-serif&quot;; color: windowtext;">
    <a moz-do-not-send="true" class="moz-txt-link-abbreviated"
 href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>
[<a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="mailto:users-bounces@lists.ironpython.com">mailto:users-bounces@lists.ironpython.com</a>]
    <b>On Behalf Of </b>Lukas
Cenovsky<br>
    <b>Sent:</b> Friday, November 13, 2009 5:42 AM<br>
    <b>To:</b> Discussion of IronPython<br>
    <b>Subject:</b> Re: [IronPython] .NET attributes for methods<o:p></o:p></span></p>
    </div>
    </div>
    <p class="MsoNormal"><o:p> </o:p></p>
    <p class="MsoNormal" style="margin-bottom: 12pt;">This looks very
promising but I
cannot make it work. I have changed product.py in DevHawk's example to:<o:p></o:p></p>
    <pre>#from clrtypeold import ClrMetaclass<o:p></o:p></pre>
    <pre>import clrtype<o:p></o:p></pre>
    <pre><o:p> </o:p></pre>
    <pre>class Product(object):<o:p></o:p></pre>
    <pre>  #__metaclass__ = ClrMetaclass<o:p></o:p></pre>
    <pre>  __metaclass__ = clrtype.ClrClass<o:p></o:p></pre>
    <pre>  _clrnamespace = "DevHawk.IronPython.ClrTypeSeries"<o:p></o:p></pre>
    <pre>  #_clrproperties = {<o:p></o:p></pre>
    <pre>    #"name":str,<o:p></o:p></pre>
    <pre>    #"cost":float,<o:p></o:p></pre>
    <pre>    #"quantity":int,<o:p></o:p></pre>
    <pre>    #}<o:p></o:p></pre>
    <pre>    <o:p></o:p></pre>
    <pre>  def __init__(self, name, cost, quantity):<o:p></o:p></pre>
    <pre>    self.name = name<o:p></o:p></pre>
    <pre>    self.cost = cost<o:p></o:p></pre>
    <pre>    self.quantity = quantity<o:p></o:p></pre>
    <pre>    <o:p></o:p></pre>
    <pre>  def calc_total(self):<o:p></o:p></pre>
    <pre>    return self.cost * self.quantity<o:p></o:p></pre>
    <pre><o:p> </o:p></pre>
    <pre>  @property<o:p></o:p></pre>
    <pre>  @clrtype.accepts()<o:p></o:p></pre>
    <pre>  @clrtype.returns(str)<o:p></o:p></pre>
    <pre>  def name(self):<o:p></o:p></pre>
    <pre>      return self._name<o:p></o:p></pre>
    <pre><o:p> </o:p></pre>
    <pre>  @name.setter<o:p></o:p></pre>
    <pre>  @clrtype.accepts(str)<o:p></o:p></pre>
    <pre>  @clrtype.returns()<o:p></o:p></pre>
    <pre>  def name(self, value):<o:p></o:p></pre>
    <pre>      self._name = value<o:p></o:p></pre>
    <pre><o:p> </o:p></pre>
    <p class="MsoNormal" style="margin-bottom: 12pt;">When I run it I
don't see any
items in the listbox. When I check the name, it is a property:<o:p></o:p></p>
    <pre><span class="silverlightdlrreplprompt">py&gt;</span> a.root.listbox1.Items[0]<o:p></o:p></pre>
    <div>
    <pre>=&gt; &lt;Product object at 0x000000000000002B&gt;<o:p></o:p></pre>
    </div>
    <pre><span class="silverlightdlrreplprompt">py&gt; </span>a.root.listbox1.Items[0].GetType().GetProperties()<o:p></o:p></pre>
    <div>
    <pre>=&gt; Array[PropertyInfo]((&lt;System.Reflection.RuntimePropertyInfo object at 0x000000000000002C [System.String name]&gt;))<o:p></o:p></pre>
    </div>
    <pre><o:p> </o:p></pre>
    <p class="MsoNormal">Whe I used the old clrtype with _clrproperties
=
{'name':
str, ...}, it worked.<br>
    <br>
--<br>
-- Luká¹<br>
    <br>
    <br>
Shri Borde wrote: <o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">Here
is an updated version of clrtype.py that uses @property +
@clrtype.accepts/@clrtype.returns to indicate a CLR property, instead
of using
&#8220;_clrproperties&#8221;. I think its more Pythonic in general, but also
you should be able to modify @notify_property to work with it. </span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"> </span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">Note
that notify_property won&#8217;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:</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"> </span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">class
notify_property(property):</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"> </span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">   
    <span
 style="background: yellow none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">def
propagate_attributes(old_function, new_function):</span></span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="background: yellow none repeat scroll 0% 50%; font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">       
new_function.func_name = old_function.func_name</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="background: yellow none repeat scroll 0% 50%; font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">       
new_function.arg_types = old_function.arg_types</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="background: yellow none repeat scroll 0% 50%; font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">       
new_function.return_type = old_function.return_type</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"> </span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">   
def __init__(self, getter):</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">       
def newgetter(slf):</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
try:</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">               
return getter(slf)</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
except AttributeError:</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">               
return None</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">       
    <span
 style="background: yellow none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">propagate_attributes(getter,
newgetter)</span></span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">       
super(notify_property, self).__init__(newgetter)</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"> </span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">   
def setter(self, setter):</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">       
def newsetter(slf,
newvalue):</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
oldvalue = self.fget(slf)</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
if oldvalue != newvalue:</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">               
setter(slf, newvalue)</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">               
slf.OnPropertyChanged(setter.__name__)</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">       
    <span
 style="background: yellow none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">propagate_attributes(setter,
newsetter)</span></span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">       
return property(</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
fget=self.fget,</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
fset=newsetter,</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
fdel=self.fdel,</span><o:p></o:p></p>
    <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">           
doc=self.__doc__)</span><o:p></o:p></p>
    </div>
  </blockquote>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>
  </pre>
</blockquote>
<br>
</body>
</html>