PC Review


Reply
Thread Tools Rate Thread

DefaultValueAttribute And Array Properties

 
 
Mythran
Guest
Posts: n/a
 
      25th Aug 2006
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


 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      26th Aug 2006
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


"Mythran" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| 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
|
|


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DefaultValueAttribute --== Alain ==-- Microsoft VC .NET 2 26th Oct 2006 02:08 AM
DefaultValueAttribute usage Edward Diener Microsoft Dot NET Framework 1 11th Sep 2006 06:34 AM
DefaultValueAttribute And Array Properties Mythran Microsoft VB .NET 1 26th Aug 2006 02:01 AM
DefaultValueAttribute Dulovits M. Microsoft C# .NET 1 3rd Jun 2004 06:38 PM
VS Designer and DefaultValueAttribute Gianluca Microsoft Dot NET 0 25th Feb 2004 02:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:52 AM.