Home All Groups Group Topic Archive Search About

DefaultValueAttribute And Array Properties

Author
25 Aug 2006 4:12 PM
Mythran
How can I set a DefaultValue for an array property?  I don't have a project
that uses this anymore, but still am curious.  Of all the replies I've
posted here, a simple thing like this is my "gotcha!".  :***(

I have a TypeConverter class that inherits from ArrayConverter and it parses
a string into an integer-array.  The property that gets/sets the array has
the TypeConverter attribute assigned to this type-converter.  One of the
constructor overloads for the DefaultValueAttribute is DefaultValue(Type,
Value) where Type is the type that has a TypeConverter to use to convert
Value to the specified Type.

Well, my TypeConverter isn't the converter for the integer-array type ;(  So
I don't believe using that overload is what I need...even though
theoretically, it's the closest thing I've got ...

Thanks,
Mythran

Author
26 Aug 2006 1:01 AM
Jay B. Harlow [MVP - Outlook]
Mythran,
I'm not sure if you can use a DefaultValue for an array property. Nor am I
sure if you even should.

Generally what I use is a ShouldSerialize function and a Reset method,
something like:

    Public Property Something() As String()
        Get
            Return ...
        End Get
        Set(ByVal value As String())
            ...
        End Set
    End Property

    Public Sub ResetSomething()
        ...
    End Sub

    Public Function ShouldSerializeSomething() As Boolean
        return ...
    End Function

Where ResetSomething will reset the value back to the default for the
Something Property. While ShouldSerializeSomething returns True if the
Something is not at its default value.

I don't have the MSDN link handy that explains the above methods...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"Mythran" <kip_pot***@hotmail.com> wrote in message
news:utiKOFGyGHA.4392@TK2MSFTNGP04.phx.gbl...
| How can I set a DefaultValue for an array property?  I don't have a
project
| that uses this anymore, but still am curious.  Of all the replies I've
| posted here, a simple thing like this is my "gotcha!".  :***(
|
| I have a TypeConverter class that inherits from ArrayConverter and it
parses
| a string into an integer-array.  The property that gets/sets the array has
| the TypeConverter attribute assigned to this type-converter.  One of the
| constructor overloads for the DefaultValueAttribute is DefaultValue(Type,
| Value) where Type is the type that has a TypeConverter to use to convert
| Value to the specified Type.
|
| Well, my TypeConverter isn't the converter for the integer-array type
;(  So
| I don't believe using that overload is what I need...even though
| theoretically, it's the closest thing I've got ...
|
| Thanks,
| Mythran
|
|