By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Shipping configuration parameters along a library

P: n/a
I am currently implementing a scientific library in C#. The algorithms
include some system dependent tuning parameters (lets say memory vs. speed
parameters for example). Since, those parameters are quite numerous, it
would be cumbersome for the client of the library to be forced to provide
explicit values for all those parameters. Also, default parameters should be
provided by the library itself. But I would rather not "hard code" such
parameters. I think, a good solution would be somehow to ship a (XML)
configuration file along the library. This way, the default performance of
the library could still be tuned after compilation.

To do this, there are a lot of dirty home-made solutions. But I think, this
issue should have some classical solutions (using System.Resource or
System.Configuration ???). Does someone have a convenient solution for this
problem ?

Thank you for the help,
Joannes Vermorel
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Place your configuration settings into their own class, and you can use
XMLSerializer (described in Visual Studio Help) to read and write an object
of the class to an XML file.

Give your class a constructor that initialises the default settings. That
way, you can easily use these if the XML file doesn't exist.

Here's a simple example of the class to be serialised. (In production code,
you'd probably want to use properties instead of public variables.)

[Serializable]
public class MySettings
{
public bool bFavourSpeedOverSize;
public bool bOptimiseForSomeProcessor;

public MySettings()
{
this.SetDefaults();
}

public void SetDefaults()
{
bFavourSpeedOverSize = true;
bOptimiseForSomeProcessor = false;
}
}

P.

--
www.CL4.org
Nov 15 '05 #2

P: n/a
Place your configuration settings into their own class, and you can use
XMLSerializer (described in Visual Studio Help) to read and write an object
of the class to an XML file.

Give your class a constructor that initialises the default settings. That
way, you can easily use these if the XML file doesn't exist.

Here's a simple example of the class to be serialised. (In production code,
you'd probably want to use properties instead of public variables.)

[Serializable]
public class MySettings
{
public bool bFavourSpeedOverSize;
public bool bOptimiseForSomeProcessor;

public MySettings()
{
this.SetDefaults();
}

public void SetDefaults()
{
bFavourSpeedOverSize = true;
bOptimiseForSomeProcessor = false;
}
}

P.

--
www.CL4.org
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.