[Mono-osx] [MonoMac] PopupBindings Sample

kjpou kjpou at pt.lu
Sat Nov 27 03:00:23 EST 2010


Hello all

Here is another attempt at making the Sample's bindings C#-ish.

With doing it this way there are no [Export(XXXX)] used and the Person 
class is very simple.  The binding in IB are mapped directly to Person 
properties.

Implementing the sample this way I was thinking that maybe the 
NSObject2.cs class could be extended with some helper methods of the form:

         public virtual bool CanConvertFrom(Type sourceType)

         public virtual bool CanConvertTo(Type destinationType)

         public virtual object ConvertFrom(object value)

         public virtual object ConvertTo(Type destinationType)

Then in each Class that derives from NSObject could override these 
methods with their specific implementation that corresponds to what the 
class accepts in their respective -> public static implicit operator <- 
implementations.

At the very least a default type converter in the genre of the provided 
MonoMacTypeConverter.cs class provided.  That way developers would have 
a lot of the implementation hidden as was suggested below.

Just throwing some ideas out there.

Kenneth

On 11/23/10 3:40 PM, Miguel de Icaza wrote:
> Hello,
>
>     I at first write the Person.cs class with C# native type but what
>     I found myself doing all the time was converting to and from
>     native to NSString all over the place so thought that made the
>     code messy.  For instance in the SetValueForKey method.  If those
>     methods should be using string instead of NSString I could change
>     them when I find them.
>
>
> We should change that, and then introduce a "LowLevelSetValueForKey" 
> if we need, like we do in NSDictionary for those that want to pass 
> handles directly.
>
>     I totally agree with you on the C# 3 features.  One of the
>     questions that I was going to post was how to get around the
>     NSDictionary use and convert back and forth to native Dictionary
>     types easily.  I guess I am missing that part to start using more
>     of the C# features.  An example would definitely be welcome on how
>     to go about that.
>
>
> The good news is that NSDictionary implements IDictionary, so we can 
> always treat NSDictionary in a .NET way.
>
> The problem is that it comes with some overhead, so it might be a good 
> idea to write NSDictionary->Dictionary and back helper methods.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20101127/1a2ce84e/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PopupBindings.zip
Type: application/zip
Size: 2036804 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-osx/attachments/20101127/1a2ce84e/attachment-0001.zip 


More information about the Mono-osx mailing list