-
Notifications
You must be signed in to change notification settings - Fork 7
/
NCldrBuilder.GetDescriptions.cs
55 lines (46 loc) · 1.84 KB
/
NCldrBuilder.GetDescriptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using NCldr.Types;
namespace NCldr.Builder
{
public partial class NCldrBuilder
{
private static T[] GetDescriptions<T>(string filename, string nameCode, string progressName) where T: IDescription, new()
{
if (options != null && (filename == "currency" && !options.IncludeCurrencies))
{
return null;
}
XDocument bcp47Document = GetXmlDocument(String.Format(@"common\bcp47\{0}.xml", filename));
XElement keyElement = (from i in bcp47Document.Elements("ldmlBCP47").Elements("keyword").Elements("key")
where i.Attribute("name").Value.ToString() == nameCode
select i).FirstOrDefault();
if (keyElement == null)
{
return null;
}
List<XElement> elements = (from i in keyElement.Elements("type")
select i).ToList();
if (elements == null || elements.Count == 0)
{
return null;
}
List<T> list = new List<T>();
foreach (XElement element in elements)
{
string name = element.Attribute("name").Value.ToString();
Progress(String.Format("Adding {0}", progressName), name);
T item = new T();
item.Id = name;
item.Description = element.Attribute("description").Value.ToString();
list.Add(item);
Progress(String.Format("Added {0}", progressName), name, ProgressEventType.Added, item);
}
return list.ToArray();
}
}
}