Note while this is the current behavior we actually want to introduce a 
breaking change in 2.0 that alters this.  What we really want to do is not 
expose all protected members but instead only expose protected members after 
you've subclassed the type.  So Derived().WeakName = 'abc' would still fail, 
but:

class x(Derived): pass

x().WeakName = 'abc'

would work.  One reason is that it makes a little more sense - another reason 
is we can't actually enable the current behavior in Silverlight at all because 
it requires full trust.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Foord
Sent: Wednesday, May 14, 2008 2:37 PM
To: Discussion of IronPython
Subject: Re: [IronPython] protected set { }

Matthew Barnard wrote:
> public abstract class Object
> {
>     protected string weakName = string.Empty;
>
>     public string WeakName
>     {
>         get { return this.weakName; }
>         protected set { this.weakName = value; }
>     }
> }
>
> public class Derived
> {
>     public Derived()
>     {
>         this.WeakName = "Hello";
>     }
> }
>
> In C#:
> Derived obj = new Derived();
> Console.WriteLine(obj.WeakName)
> Hello
> obj.WeakName = "Fail";
> The property or indexer 'Object.WeakName' cannot be used in this
> context because the set accessor is inaccessible
>
> In IPy:
> >>> obj = Derived()
> >>> obj.WeakName = 'Succeed'
> >>> obj.WeakName
> 'Succeed'
>
> Is this expected behavior?

Yes.

Michael Foord

>
> ___________________________
> Matthew Barnard
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to