Guest User

language class

a guest
Jul 31st, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using System.Xml.Serialization;
  5.  
  6. namespace Utils
  7. {
  8.     /// <summary>
  9.     /// Represents an object of language for the localization.
  10.     /// </summary>
  11.     [Serializable]
  12.     public class Language
  13.     {
  14.         /// <summary>
  15.         /// Represents a pair of language text
  16.         /// </summary>
  17.         [Serializable]
  18.         public struct Text
  19.         {
  20.             private string _Key;
  21.             private string _Value;
  22.  
  23.             /// <summary>
  24.             /// Sets or gets the key of this pair.
  25.             /// </summary>
  26.             [XmlAttribute]
  27.             public string Key
  28.             {
  29.                 get { return _Key; }
  30.                 set { _Key = value; }
  31.             }
  32.  
  33.             /// <summary>
  34.             /// Sets or gets the value of this pair.
  35.             /// </summary>
  36.             [XmlAttribute]
  37.             public string Value
  38.             {
  39.                 get { return _Value; }
  40.                 set { _Value = value; }
  41.             }
  42.  
  43.             /// <summary>
  44.             /// Initializes a new instance of the Text structure with the specified key and value.
  45.             /// </summary>
  46.             /// <param name="key">The key of the pair.</param>
  47.             /// <param name="value">The value of the pair.</param>
  48.             public Text(string key, string value)
  49.             {
  50.                 _Key = key;
  51.                 _Value = value;
  52.             }
  53.         }
  54.  
  55.         /// <summary>
  56.         /// Sets or gets the name.
  57.         /// </summary>
  58.         public string Name
  59.         {
  60.             set;
  61.             get;
  62.         }
  63.  
  64.         /// <summary>
  65.         /// Gets the list of the text pairs.
  66.         /// </summary>
  67.         public List<Text> Texts
  68.         {
  69.             private set;
  70.             get;
  71.         }
  72.  
  73.         /// <summary>
  74.         /// Initializes a new instance of Language.
  75.         /// </summary>
  76.         public Language()
  77.         {
  78.             Texts = new List<Text>();
  79.             Name = string.Empty;
  80.         }
  81.  
  82.         /// <summary>
  83.         /// Initializes a new instance of Language with the specified name.
  84.         /// </summary>
  85.         /// <param name="name">Name of the language.</param>
  86.         public Language(string name) : this()
  87.         {
  88.             Name = name;
  89.         }
  90.  
  91.         /// <summary>
  92.         /// Save this language into the XML file specified.
  93.         /// </summary>
  94.         /// <param name="path">Path of the XML file where to save this object.</param>
  95.         public void Save(string path)
  96.         {
  97.             Serializer<Language>.Serialize(this, path);
  98.         }
  99.  
  100.         /// <summary>
  101.         /// Open the XML file specified to load the language contained in.
  102.         /// </summary>
  103.         /// <param name="path">Path of the XML file where an object of language is saved.</param>
  104.         /// <returns>Returns a Language object representig the XML file specified.</returns>
  105.         public Language Load(string path)
  106.         {
  107.             return Serializer<Language>.Dezerialize(path);
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment