Search code examples
c#-4.0catel

SavableModelBase<> Load/Save - "cleaner" XML or configuration tool?


I am working on a system that should be "plug-able" - the user should be able to specify the various parts that interact in it ("composable application").

As part of the application I have a concept of "processor" that should be configured with relevant configuration class.

e.g.:

<processors>
    <processor type="SomeAsm.SomeType1">
        <configuration>
            <SomeType1Prop1>value</SomeType1Prop1>
        </configuration>
    </processor>
    <processor type="OtherAsm.SomeType2">
        <configuration>
            <SomeType2Prop1>value</SomeType2Prop1>
            <SomeType2Prop2>value</SomeType2Prop2>
        </configuration>
    </processor>
</processors>

(Of course SomeAsm.SomeType1 and OtherAsm.SomeType2 share some common interface or base class)

I considered using System.Configuration but there are some shortcoming - (1) I have to explicitly work with the various classes in the namespace (e.g. ConfigurationElement, ConfigurationElementsCollection etc) and (2) in order to support "any" configuration class instance, I need to implement some factory while de-serializing.

An alternative to that is Catel's (awesome) SavableModelBase<> class which has a Save/Load methods that are very convenient and easy to use. The only shortcoming I see with this method is that the XML itself is somewhat "verbose" and is hard to edit it manually.

Is there some way to control the "extra" markup omitted to the file (e.g. remove namespaces (xmlns:ctl2="http://schemas.datacontract.org/2004/07/InheritedConfiguration.CatelConfig" and then ctl2:SomeType2Prop1) and graphid (graphid="5"))?

Alternatively, is there some "global" editor that I can use?

Thanks,

Tomer


Solution

  • The reason the xml of Catel is a bit bloated is because it uses DataContractSerializer under the hood. From the top of my head, there is an optimization option in the serializer, but not sure if that is worth the trouble.

    Another option you could look at is the IConfigurationService in Catel, it does most if it for you as well under the hood and is stored as a key/value collection.