Verbos configurables en tiempo de ejecución según la especificación

I have an application that adheres to multiple specifications that are very similar but require different verbs for identical actions. For example, one spec says jump, while the other might say hop.

Estoy buscando algo como CultureInfo (o posiblemente incluso CultureInfo but I feel that would be bad practice) to define these verbs. It must be configurable at runtime (spec change shouldn't require a re-compile).

preguntado el 30 de enero de 12 a las 19:01

"jump" and "hop" seem to belong both to the same culture. Using CultureInfo you can differentiate different languages, countries, etc., but not arbitrary specifications. -

@Olivier Right, but I want it to act similar to CultureInfo, just with specifications. -

1 Respuestas

You could use a xml file in order to store the verbs

<?xml version="1.0" encoding="UTF-8" ?>
<verbs>
    <verb name="jump", spec="spec1">jump</verb>
    <verb name="jump", spec="spec2">hop</verb>
    <verb name="consume_food", spec="spec1">eat</verb>
    <verb name="consume_food", spec="spec2">feed</verb>
</verbs>

or organized by specification

<?xml version="1.0" encoding="UTF-8" ?>
<specs>
    <spec name="spec1">
        <verb name="jump">jump</verb>
        <verb name="consume_food">eat</verb>
    </spec>
    <spec name="spec2">
        <verb name="jump">hop</verb>
        <verb name="consume_food">feed</verb>
    </spec>
</specs>

Or use a different file for every specification

File: spec1.xml

<?xml version="1.0" encoding="UTF-8" ?>
<verbs>
    <verb name="jump">jump</verb>
    <verb name="consume_food">eat</verb>
</verbs>

File: spec2.xml

<?xml version="1.0" encoding="UTF-8" ?>
<verbs>
    <verb name="jump">hop</verb>
    <verb name="consume_food">feed</verb>
</verbs>

Finally, in a separate configuration file, define which specification was selected. It could be a plain text file containing just the name of the specification or it could be another xml file containing different application settings.

Personally I find it handy to use an old style ini-file. It is easy to read and to change, even by no-programmers.

Respondido el 31 de enero de 12 a las 00:01

This is what I'm going to end up doing if the functionality doesn't already exist in C#. XML will be fine as my users are (or should be) familiar with it. - Mike Park

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.