Type converter

Posts   
 
    
chungpn
User
Posts: 39
Joined: 23-Mar-2011
# Posted on: 04-May-2011 11:29:13   

Does someone implement a type converter which converts a byte array into an image and vice versa? I have these code but it not work

public class ImageToByteConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {

       // if (sourceType == typeof(byte[]))
        switch (sourceType.FullName)
        {
            case "System.Byte[]":
                return true;
            default:
                return false;
        }

    }

    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {

        switch (destinationType.FullName)
        {
           case "System.Byte[]":
                return true;
            default:
                return false;
        }
    }

    public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
    {



                if (value == null)
                {
                    return null;
                }
                else
                {
                    ImageConverter cnv = new ImageConverter();
                    return cnv.ConvertFrom(value);
                }

        }

    }

    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {


        if(value == null) {
            return null;
        } else {
            ImageConverter cnv = new ImageConverter();
            return cnv.ConvertTo(value,Type.GetType("System.Byte[]"));
        }
    }

    public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues)
    {
        return new byte[0];
    }
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-May-2011 15:36:08   

Your question is not clear enough.

Which part does not work? Which LLBLGen Pro runtime library version (build no.) are you using?

What's the database field type?

Also try to return null in CreateInstance().

chungpn
User
Posts: 39
Joined: 23-Mar-2011
# Posted on: 04-May-2011 16:16:24   

I use llblgen 3.1 February 7th, 2011 the database field field type is vabinary(MAX)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-May-2011 16:37:18   

Walaa wrote:

Which part does not work?

You missed the above question.