src/EasyFrameWork/Mvc/DataAnnotations/LocalizeString.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Easy.Extend;
using Easy.Serializer;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace Easy.Mvc.DataAnnotations
{
    public class LocalizeString : IStringLocalizer
    {
        private readonly MetaData.ViewConfigure _viewConfigure;
        public LocalizeString(Type modelType)
        {
            if (modelType.IsClass)
            {
                _viewConfigure = ServiceLocator.GetViewConfigure(modelType);
            }
        }
        public LocalizedString this[string name] => throw new NotImplementedException();

        public LocalizedString this[string name, params object[] arguments]
        {
            get
            {
                if (_viewConfigure != null)
                {
                    var mapping = JsonConverter.Deserialize<Mapping>(Encoding.UTF8.GetString(Convert.FromBase64String(name)));
                    var descriptor = _viewConfigure.GetViewPortDescriptor(mapping.Property);
                    if (descriptor != null)
                    {
                        foreach (var item in descriptor.Validator)
                        {
                            if (item.Name == mapping.ValidatorName)
                            {
                                return new LocalizedString(name, item.ErrorMessage);
                            }
                        }
                    }
                }

                return new LocalizedString(name, name);
            }
        }

        public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
        {
            throw new NotImplementedException();
        }

        public IStringLocalizer WithCulture(CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
后面还有 1 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。