473,385 Members | 1,359 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,385 software developers and data experts.

Retrieving the DefaultValue for a property from a function ..?

Hi folks,

I'd like to retrieve default values for properties (of a user control) via
code instead of having string-constants.

Consider the following (simplified) property:

Private _MyColor as Color

<DefaultValue(GetType(Color), "1, 2, 3")_
Public Property MyColor() As System.Drawing.Color
Get
Return _MyColor
End Get
Set(ByVal value As System.Drawing.Color)
_MyColor = value
End Set
End Property
Public Sub ResetMyColor()
'...
End Sub
Public Function ShouldSerializeMyColor() As Boolean
'...
End Function

The default-value for the above prop is set to "1, 2, 3". I'd like to not
have that value be specified in the property itself but rather in a
different class that defines the values.
Is there any way to achieve this ..?

The reason for this is actually pretty simple - there is a bunch of
user-controls in my ClassLib. All controls therein share a common set of
colors that is to be used per default. To have all colors in a central
place (in case values need to be changed) I created a class that exposes a
GetColor-function and takes an enum. If anyone can come up with a better
approach, I'd be happy as well! :-)

Cheers,
Olaf
Jun 27 '08 #1
1 1125
On 2008-05-07, Olaf Rabbachin <Ol*********@IntuiDev.comwrote:
Hi folks,

I'd like to retrieve default values for properties (of a user control) via
code instead of having string-constants.

Consider the following (simplified) property:

Private _MyColor as Color

<DefaultValue(GetType(Color), "1, 2, 3")_
Public Property MyColor() As System.Drawing.Color
Get
Return _MyColor
End Get
Set(ByVal value As System.Drawing.Color)
_MyColor = value
End Set
End Property
Public Sub ResetMyColor()
'...
End Sub
Public Function ShouldSerializeMyColor() As Boolean
'...
End Function

The default-value for the above prop is set to "1, 2, 3". I'd like to not
have that value be specified in the property itself but rather in a
different class that defines the values.
Is there any way to achieve this ..?

The reason for this is actually pretty simple - there is a bunch of
user-controls in my ClassLib. All controls therein share a common set of
colors that is to be used per default. To have all colors in a central
place (in case values need to be changed) I created a class that exposes a
GetColor-function and takes an enum. If anyone can come up with a better
approach, I'd be happy as well! :-)

Cheers,
Olaf
You can use reflection to get at attribute information and values. Look
at PropertyInfo.GetCustomAttributes for more information.

--
Tom Shelton
Jun 27 '08 #2

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

Similar topics

14
by: Maurice Mertens | last post by:
Hi, I have an Access database in which I defined default values for certain columns. On my windows forms I've got controls bound to the dataset, The problem is that when I add a new row to the...
5
by: schneider | last post by:
Hello, Have an issue with a property using the DefaultValue(True) attribute. Imports System.ComponentModel Public Class Class1 Private m_testValue As Boolean
0
by: Carlo, MCP | last post by:
Good morning, sorry for the lenght of the code, but it's six months that I've this problem. The following code is an extreme simplification of the original code, that is much more complex. The...
3
by: MLH | last post by:
On frmVehicleEntryForm... I wanted to change the DefaultValue property of one of my textbox controls on a form from within code. I wanted the setting to be no setting - as if nothing had ever...
0
by: Shadow Lynx | last post by:
Language: VB.Net 2.0 (Windows Application) IDE: MS VB 2005 Exp. Ed. Summary: Setting a DefaultValue of type Decimal for the Property of a UserControl does not work properly - the value appears...
10
by: tony | last post by:
Hello!! I have some demo programs written in C# and they have this construction "" see below. I haven't seen this before so what does it mean ? public bool ShowDropDownButtons { get {...
6
by: Peter Hartlén | last post by:
Hi! What's the correct syntax for the default value design time attribute, using classdiagram view and Custom Attributes dialog. For a boolean: DefaultValue(true) DefaultValue("true")...
6
by: MLM450 | last post by:
Is it possible to retrieve an item's "sizeconst" value dynamically? I have the following member defined in a class: private char units; I want the code that values the units member to know...
3
by: Johnny Jörgensen | last post by:
Does anybody know how to correctly specify the defaultvalue attribute for a property whose type is an enum. Example: Public Enum TestValues Value1=1 Value2=2 End Enum
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: 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...

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.