Hello,

Value transformers are used through an indirection by name (see the
NSValueTransformer documentation). The trick is to register the value
transformer before it is referenced by its name.

You should take a look at the following sample code:
http://developer.apple.com/samplecode/TemperatureTester/index.html#//apple_ref/doc/uid/DTS10003705

The value transformers registration is performed in the "initialize"
static method of the application delegate. When the class is loaded in
the runtime, the value transformers are registered.

Regards, Laurent Etiemble.

2009/4/16 Nico Van Laerebeke <crazy...@gmail.com>:
> I was wondering if/how it was possible to use value transformers in monobjc?
>
> After working with binding I needed a value transformer,  I’ve read
> the apple developer documentation about valuetransformers(
> http://developer.apple.com/documentation/Cocoa/Conceptual/ValueTransformers/ValueTransformers.html
> ) but was not able to get it working.
>
> I’ve tried the following as a simple test:
>
> Creating an NSTestTransformer class by subclassing NSValueTransformer.
>
>
>
> using System;
>
> using Monobjc;
> using Monobjc.Cocoa;
>
> namespace TransformerTest {
>    [ObjectiveCClass]
>    public class NSTestTransformer : NSValueTransformer {
>        public NSTestTransformer() : base() { }
>        public NSTestTransformer(IntPtr native_object) : base(native_object) { 
> }
>
>
>        public Class transformedValueClass {
>            get {
>                return Class.GetClassFromObject(new NSString()); }
>        }
>
>        public bool AllowsReverseTransformation {
>            get {
>                return false;
>            }
>        }
>
>        public Id TransformedValue(Id pValue) {
>            return (new NSString("teststring")).Self;
>        }
>
>        public Id reverseTransformedValue(Id pValue) {
>            return (new NSString("reversetransformedstring")).Self;
>        }
>    }
> }
>
> I think this should be correct, but I'm unsure on how and where to
> register this custom transformer.
>
>
> Any suggestions?
>
>
> Thanks,
> Nico
>

Reply via email to