Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReportingStringLocalizer.cs
1using Microsoft.Extensions.Localization;
2using System.Diagnostics;
3using System.Globalization;
4using System.Reflection;
5
7{
8 public interface IReportingStringLocalizer : IStringLocalizer
9 {
10
11 LocalizedString this[string Name, bool ShouldReport] { get; }
12
13 LocalizedString this[string Name, bool ShouldReport, params object[] Arguments] { get; }
14 }
15
20 public class ReportingStringLocalizer(IStringLocalizer Localizer) : IReportingStringLocalizer
21 {
22 private readonly IStringLocalizer localizer = Localizer;
23
24 public LocalizedString this[string Name]
25 => ((IReportingStringLocalizer)this)[Name, true];
26
27 public LocalizedString this[string Name, params object[] Arguments]
28 => ((IReportingStringLocalizer)this)[Name, true, Arguments];
29
30 LocalizedString IReportingStringLocalizer.this[string Name, bool ShouldReport]
31 {
32 get
33 {
34 LocalizedString Result = this.localizer[Name];
35 if (Result is not null && !Result.ResourceNotFound)
36 return Result;
37
38 StackTrace Trace = new();
39 Type Caller = typeof(ServiceRef);
40 int i, c = Trace.FrameCount;
41 Assembly ThisAssembly = typeof(App).Assembly;
42
43 for (i = 1; i < c; i++)
44 {
45 Type? T = Trace.GetFrame(i)?.GetMethod()?.DeclaringType;
46 if (T is null)
47 continue;
48
49 if (T.Assembly.FullName == ThisAssembly.FullName)
50 {
51 if (T == typeof(ReportingStringLocalizer))
52 continue;
53
54 if (T.IsConstructedGenericType)
55 T = T.GetGenericTypeDefinition();
56
57 Caller = T;
58 break;
59 }
60 }
61
62 if (ShouldReport)
63 LocalizeExtension.ReportMissingString(Name, Caller);
64
65 return new LocalizedString(Name, Name, true);
66 }
67 }
68
69 LocalizedString IReportingStringLocalizer.this[string Name, bool ShouldReport, params object[] Arguments]
70 {
71 get
72 {
73 LocalizedString Result = this[Name];
74 if (Result.ResourceNotFound)
75 return Result;
76
77 return new LocalizedString(Name, string.Format(CultureInfo.CurrentCulture, Result.Value, Arguments));
78 }
79 }
80
81 public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
82 {
83 return this.localizer.GetAllStrings(includeParentCultures);
84 }
85 }
86}
Represents an instance of the Neuro-Access app.
Definition: App.xaml.cs:125
Base class that references services in the app.
Definition: ServiceRef.cs:43