Menu

#12 Ability to read additional attributs on sections and setting

open
None
5
2005-04-26
2005-04-25
Anonymous
No

I love Nini and have used it on several projects I have
worked on. The current application I am writing requires
me to define public configuration entries and private
entries. Basically I am creating a configuration
application that will read another apps config file, parse
it and then present a UI for modifying values. Each
setting will have a parameter to specify the type of
setting it is, i.e. Text, Numeric, Boolean. The app would
then choose the appropriate editor for the value type.

I need to be able to read (and write) custom attributes
on sections and settings. Below is a sample of what my
configu file will look like.

<?xml version="1.0" encoding="utf-8" ?>
<Nini>
<Section Name="settings" Alias="Application
Settings">
<Key Name="SearchName"
Value="Search:" Type="Text"/>
<Key Name="Volume" Value="10" Type="Slider"/>
</Section>
</Nini>

I think this would be a great addition. Thank you.

Discussion

  • Brent R. Matzelle

    • assigned_to: nobody --> bmatzelle
     
  • Brent R. Matzelle

    Logged In: YES
    user_id=163900

    Hello. Thanks for the kind words about Nini. I appreciate
    it very much.

    You bring up some interesting points about the architecture
    of Nini. I specifically kept non-key/value pair information
    out of the product because that is all that is supported in
    the base configuration file types (INI, Registry, .NET
    .configs). I have thought of adding some type of meta-data
    to the documents but I am still unsure of how this would fit
    into the API.

    My suggestion for your purposes would be to add this:

    <Section Name="settings">
    <Key Name="settings:Alias" Value="Application
    Settings">
    </Section>

    In the above example you can get the Alias property by
    looking for a special property like this:

    IConfig config = source.Configs["settings"];
    string alias = config.Get(config.Name + ":Alias");

    This would allow you to automatically grab section
    properties with a method like so:

    string GetAlias (IConfig config)
    {
    return config.Get(config.Name + ":Alias");
    }

    string alias = GetAlias (config);

    As for the Volume example you could do something of the same
    nature:
    <Key Name="Volume" Value="10"/>
    <Key Name="Volume:Type" Value="Slider"/>

    Is this useful?

     
  • Nobody/Anonymous

    Logged In: NO

    I don't think that will work. Let me explain why. The
    application I am writing does not know what configuration
    settings an applicaction will have. I guess I could do some
    string comparisons and look for "Root" settings by finding
    Keys without : in them but I don't like forceing a square peg
    into a round hole.

    I guess, since I only use the XmlConfigSource and not the INI
    nor Registry I could just extend or modify your
    XmlConfigSource.

    Nini is LGPL right? Would you mind if I borrowed your code
    and used it as a base for my own XML config library?

     

Log in to post a comment.