473,466 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Custom configuration section: How to get null for non required properties?

In the following sample I declared a custom configuration section within my
app.config. As you can see, the lastName attribute of the second employee
element is missing:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Employees" type="CustomConfigurationTest.MyConfigSection,
CustomConfigurationTest" />
</configSections>
<Employees>
<Employee EmployeeID="1" FirstName="John" LastName="Doe" />
<Employee EmployeeID="2" FirstName="Jane" />
</Employees>
</configuration>

The corresponding ConfigurationElement derived class looks as follows:

public class EmployeeElement : ConfigurationElement
{
[ConfigurationProperty("EmployeeID", IsKey = true, IsRequired = true)]
public int EmployeeID
{
get { return (int)this["EmployeeID"]; }
set { this["EmployeeID"] = value; }
}
[ConfigurationProperty("FirstName", IsRequired = true)]
public string FirstName
{
get { return (string)this["FirstName"]; }
set { this["FirstName"] = value; }
}
[ConfigurationProperty("LastName", IsRequired = false)]
public string LastName
{
get { return (string)this["LastName"]; }
set { this["LastName"] = value; }
}
}

Please note that the LastName property is marked as "IsRequired=false". At
runtime the LastName property contains an empty string for the second
employee because the lastName attribute isn't specified in the app.config.
But I'd rather like to get a null value instead. Does the .NET configuration
mechanism somehow allow to get a null value for non required configuration
element properties when the corresponding attribute isn't defined? Or is
this just not possible?

Any hints are appreciated.

Best regards

Jan 5 '07 #1
0 1233

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

Similar topics

0
by: Søren Lund | last post by:
Hello, I have implemented a custom config section handler by implementing the IConfigurationSectionHandler interface. I have registered this handler in web.config and everything works fine ......
6
by: Tabi | last post by:
Hi, I want to create a custom section in my web.config that can hold my custom values. I created a section in web.config as written below. <configSections> <section name="myCustomSection"...
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
8
by: Mark A. Sam | last post by:
Hello I am working locally with Visual Web Developer 2005 Express. Before I even installed it, the information from Microsoft was that you could FTP it to a remote site and it should work. The...
1
by: npaulus | last post by:
Hi I am trying to experiment with a custom configuration section in app.config but it just doesnt work. app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections>...
2
by: Laurent Bugnion | last post by:
Hi, I like to develop custom controls for a number of webpages. These controls are often customizable, so that they can be reused in a number of situations. My question is: What is the best...
6
by: Jeff Hegedus | last post by:
I have a dll that requires some configuration data. I put the configuration data in a custom configuration section in a config file that is loaded in the installation folder of the dll. If I...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
1
by: mcstrini | last post by:
I'm trying to have my application use a special config file which is shared across servers, and want to include a custom section (for URLs of report services associated with database instances). ...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.