473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DefaultValueAttribute And Array Properties

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
Aug 25 '06 #1
1 3151
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" <ki********@hotmail.comwrote in message
news:ut**************@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
|
|
Aug 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gianluca | last post by:
Properties of inherited controls have the default value set to the value that is assigned in the InitializeComponent method in the base form class. Which is correct and useful. In the derived form...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
0
by: vthakur | last post by:
Hello: I have generated a c# proxy (client) from the WSDL. One of the class has a defaultValueAtribute. Like so: public class PersonInformationLoadRequest { public string DataSource;
2
by: Mike in Paradise | last post by:
Can you use the DefaultValueAttribute on Decimal PropertyFields? If so what is format for setting the Default value. Thanks... Example /// <summary> /// Field: increment value ///...
1
by: Mythran | last post by:
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...
2
by: --== Alain ==-- | last post by:
Hi, I would like to define the default value of my property. My property is from type Bitmap^, therefore i was thinking to do : but i does not work. how is it possible to define this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.