1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Globalization; |
6 |
using System.Reflection; |
7 |
using System.Diagnostics; |
8 |
|
9 |
namespace libxmltv.Core |
10 |
{ |
11 |
internal static class ResourceStringHelper |
12 |
{ |
13 |
internal static string GetResourceString(string key) |
14 |
{ |
15 |
//throw new NotImplementedException("GetResourceString(string key) is not implemented"); |
16 |
return GetResourceFromDefault(key); |
17 |
} |
18 |
internal static string GetResourceString(string key, params object[] values) |
19 |
{ //throw new NotImplementedException("GetResourceString(string key, params object[] values) is not implemented"); |
20 |
string resourceFromDefault = GetResourceFromDefault(key); |
21 |
return string.Format(CultureInfo.CurrentCulture, resourceFromDefault, values); |
22 |
} |
23 |
internal static string GetResourceFromDefault(string key) |
24 |
{ |
25 |
//throw new NotImplementedException("GetResourceFromDefault(string key) is not implemented"); |
26 |
string res_string = string.Empty; |
27 |
try |
28 |
{ |
29 |
string MethodName = "GetResourceFromDefault"; |
30 |
var t = typeof(Environment); |
31 |
var method = t.GetMethod(MethodName, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy); |
32 |
if (method == null) { throw new Exception("Environment.GetResourceFromDefault(string key): could not bind to method."); } |
33 |
res_string = method.Invoke(null, new object[] { key }).ToString(); |
34 |
} |
35 |
catch (Exception ex) |
36 |
{ |
37 |
Debug.WriteLine(ex.ToString()); |
38 |
throw new Exception("Environment.GetResourceFromDefault(string key): unable to retrieve default resource string.", ex); |
39 |
} |
40 |
return res_string; |
41 |
} |
42 |
} |
43 |
} |