initializing objects via an xml file

J

Joe Abou Jaoude

Hi,

I want to initialize a number of objects via an xml file, and I was
wondering if that can be done through a section in the app.config file
without the need to use another config file.

example:
if we have the class:
Public Class myClass

Public property prop1
Public property prop2

....

End Class

the config file would be something like this:
<config>
<MyClass>
<prop1>abc</prop1>
<prop2>xyz</prop2>
</MyClass>
<MyClass>
<prop1>deg</prop1>
<prop2>klm</prop2>
</MyClass>
</config>

is there a way to do that in the app.config file ?

Thank you
 
R

rowe_newsgroups

Hi,

I want to initialize a number of objects via an xml file, and I was
wondering if that can be done through a section in the app.config file
without the need to use another config file.

example:
if we have the class:
Public Class myClass

Public property prop1
Public property prop2

...

End Class

the config file would be something like this:
<config>
<MyClass>
<prop1>abc</prop1>
<prop2>xyz</prop2>
</MyClass>
<MyClass>
<prop1>deg</prop1>
<prop2>klm</prop2>
</MyClass>
</config>

is there a way to do that in the app.config file ?

Thank you

*** Sent via Developersdexhttp://www.developersdex.com***

is there a way to do that in the app.config file ?

I don't think there is an automatic way of doing this, but you could
easily write a procedure to grab the values from the app.config file
and assign them to class's properties. Everything you need should be
in the System.Xml namespace.

Thanks,

Seth Rowe
 
C

Chris Dunaway

I don't think there is an automatic way of doing this, but you could
easily write a procedure to grab the values from the app.config file
and assign them to class's properties. Everything you need should be
in the System.Xml namespace.

Thanks,

Seth Rowe

You would have to create a class derived from ConfigurationSection and
then add an entry for this class in <ConfigSections> element in the
app.config.

In code, you could then access your config section with code similar
to this:

//SaafProvisioningSection cfg =
(SaafProvisioningSection)ConfigurationManager.GetSection("SaafProvisioning");

Dim cfg As MyConfigSection =
DirectCast(ConfigurationManager.GetSection("MyConfigSection"),
MyConfigSection)

And then access the properties of the class.

Look up ConfigurationSection in the help and it should tell how to
derive from it.

Chris
 
C

Chris Dunaway

You would have to create a class derived from ConfigurationSection and
then add an entry for this class in <ConfigSections> element in the
app.config.

In code, you could then access your config section with code similar
to this:

//SaafProvisioningSection cfg =
(SaafProvisioningSection)ConfigurationManager.GetSection("SaafProvisioning");

Dim cfg As MyConfigSection =
DirectCast(ConfigurationManager.GetSection("MyConfigSection"),
MyConfigSection)

And then access the properties of the class.

Look up ConfigurationSection in the help and it should tell how to
derive from it.

Chris

Oops! Ignore commented C# line (the one with SaafProvisioningSection)
that is not needed.

Chris
 

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

Top