DefaultValueAttribute And Array Properties

  • Thread starter Thread starter Mythran
  • Start date Start date
M

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
 
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


| 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
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top