I have an int array as a property of a Web User Control. I'd like to set that property inline if possible using the following syntax:
<uc1:mycontrol runat="server" myintarray="1,2,3" />
This will fail at runtime because it will be expecting an actual int array, but a string is being passed instead. I can make myintarray
a string and parse it in the setter, but I was wondering if there was a more elegant solution.
You could also do something like this:
which will result in:
Implement a type converter, here is one, warning : quick&dirty, not for production use, etc :
and tag the property of your control :
@mathieu, thanks so much for your code. I modified it somewhat in order to compile:
You can implement a type converter class that converts between int array and string data types. Then decorate your int array property with the TypeConverterAttribute, specifying the class that you implemented. Visual Studio will then use your type converter for type conversions on your property.
Have you tried looking into Type Converters? This page looks worth a look: http://www.codeguru.com/columns/VB/article.php/c6529/
Also, Spring.Net seems to have a StringArrayConverter (http://www.springframework.net/doc-latest/reference/html/objects-misc.html - section 6.4) which, if you can feed it to ASP.net by decorating the property with a TypeConverter attribute, might work..
Seems to me that the logical—and more extensible—approach is to take a page from the
asp:
list controls: