define my configuration file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name ="AppIdiomas" type ="CR.Util.Lenguaje.IdiomaSection, CR.Util" />
</configSections>
<!-- Seccion de Idiomas-->
<AppIdiomas name ="AppIdiomas" >
<idiomas>
<add name ="en-US" Idioma ="English (United States)" />
<add name ="es-AR" Idioma ="English (Argentina)" />
</idiomas>
</AppIdiomas>
</configuration>
using System ;
using System . Collections . Generic ;
using System . Text ;
using System. Configuration ;
namespace CR. Useful . Language
{public class IdiomaConfigElement:
ConfigurationElement {public
IdiomaConfigElement ( String newName, String newIdioma )
{Name
= newName;
Language = newIdioma ;
} public
IdiomaConfigElement ()
{} public
IdiomaConfigElement ( string elementName) {
Name elementName = ;}
[ ConfigurationProperty ( "name" , DefaultValue = "English (Argentina)" , IsRequired = true , IsKey = true )]
public string Name
{
get
{
return ( string ) this [ "name" ];
}
set {
this [ "name" ] = value ;
}}
[ ConfigurationProperty ( "Language" , DefaultValue = "es-AR" , IsRequired = true)] public
Language string
{get
{
return (string ) this [ "Language" ];}
September
{
this [ "Language" ] = value;}
}}}
System using ;
using System. Collections . Generic ;
using System. Text ;
using System. Configuration ;
namespace CR. Useful . Language
{
public class IdiomaCollection: ConfigurationElementCollection
{
public IdiomaCollection () {
IdiomaConfigElement idiom = ( IdiomaConfigElement ) CreateNewElement ();}
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType . AddRemoveClearMap ;
}
}
protected override ConfigurationElement CreateNewElement ()
{
return new IdiomaConfigElement ();
}
protected override Object GetElementKey ( ConfigurationElement element )
{
return (( IdiomaConfigElement ) element ). Name ;
}
public IdiomaConfigElement this [ int index ]
{
get
{
return ( IdiomaConfigElement ) BaseGet ( index );
}
set
{
if ( BaseGet ( index ) != null )
{
BaseRemoveAt ( index );
}
BaseAdd ( index , value );
}
}
new public IdiomaConfigElement this [ string Name ] {
get {return
( IdiomaConfigElement ) BaseGet ( Name )
}}
public int IndexOf ( IdiomaConfigElement language )
{return BaseIndexOf ( language);
}}}
using System ;
using System . Collections . Generic ;
using System . Text ;
using System. Configuration ;
namespace CR. Useful . Language
{public class IdiomaSection: ConfigurationSection
{
IdiomaConfigElement language; public
IdiomaSection () {
language = new IdiomaConfigElement ();}
[ ConfigurationProperty ( "name" , DefaultValue = "Languages" , IsRequired = true , IsKey = false)] public
string Name {
get {return
(string ) this [ "name" ];}
September
{
this [ "name" ] = value ;
}}
[ ConfigurationProperty ( "languages" , IsDefaultCollection = false)] public
IdiomaCollection languages
{get {
IdiomaCollection IdiomaCollection =
( IdiomaCollection ) base [ "languages" ]
return IdiomaCollection ;}
}}}
gives me the flexibility to define attributes such languages \u200b\u200bsupported by the user interface from the application, from a xml configuration file, make my code much more extensible, and provide greater readability to be in an xml file.
This extensibility mechanism, although in this example was used for "multi-language" can be considered for any other "variable" of an application that can be configured from an xml configuration file, since the mechanism is what is important here.