示例#1
0
        public virtual IDictionary <string, object> GetHtmlLocalizerInformation(IHtmlLocalizer htmlLocalizer)
        {
            if (htmlLocalizer == null)
            {
                throw new ArgumentNullException(nameof(htmlLocalizer));
            }

            var information = new SortedDictionary <string, object>
            {
                { "Type", htmlLocalizer.GetType() }
            };

            var internalStringLocaliser = (IStringLocalizer)this.GetInternalStringLocalizer(htmlLocalizer);

            // ReSharper disable InvertIf
            if (internalStringLocaliser != null)
            {
                foreach (var item in this.GetStringLocalizerInformation(internalStringLocaliser))
                {
                    information.Add("Internal-StringLocalizer." + item.Key, item.Value);
                }
            }
            // ReSharper restore InvertIf

            return(information);
        }
示例#2
0
        protected internal virtual object GetInternalStringLocalizer(IHtmlLocalizer htmlLocalizer)
        {
            if (htmlLocalizer == null)
            {
                return(null);
            }

            var internalLocalizer = htmlLocalizer.GetType().GetField("_localizer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(htmlLocalizer);

            if (internalLocalizer is IHtmlLocalizer internalHtmlLocalizer)
            {
                return(this.GetInternalStringLocalizer(internalHtmlLocalizer));
            }

            return(internalLocalizer);
        }