コード例 #1
0
 /// <summary> 构造函数 </summary>
 /// <param name="camelCase">驼峰</param>
 /// <param name="retain">保留/排除:true为保留</param>
 /// <param name="props"></param>
 public JsonContractResolver(NamingType camelCase = NamingType.Normal, bool retain = true,
                             params string[] props)
 {
     _camelCase = camelCase;
     _retain    = retain;
     _props     = props;
 }
コード例 #2
0
 /// <summary> 构造函数 </summary>
 /// <param name="camelCase">驼峰</param>
 /// <param name="retain">保留/排除:true为保留</param>
 /// <param name="props"></param>
 public JsonContractResolver(NamingType camelCase = NamingType.Normal, bool retain = true,
     params string[] props)
 {
     _camelCase = camelCase;
     _retain = retain;
     _props = props;
 }
コード例 #3
0
        public virtual string GetConvertedName(NamingType type = NamingType.Normal, int start = 0)
        {
            var arr   = Name.Split('_');
            var sb    = new StringBuilder();
            var index = start > 0 ? start : 0;

            for (var i = index; i < arr.Length; i++)
            {
                var name = arr[i];
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }
                if (type == NamingType.Normal || i > index)
                {
                    sb.Append(name.Substring(0, 1).ToUpper());
                    if (name.Length > 1)
                    {
                        sb.Append(name.Substring(1));
                    }
                }
                else
                {
                    sb.Append(name);
                }
            }
            return(sb.ToString());
        }
コード例 #4
0
ファイル: AutoBackupModule.cs プロジェクト: osCore2/osCore2
        /// <summary>
        /// Top-level method for creating an absolute path to an OAR backup file based on what naming scheme the user wants.
        /// </summary>
        /// <param name="regionName">Name of the region to save.</param>
        /// <param name="baseDir">Absolute or relative path to the directory where the file should reside.</param>
        /// <param name="naming">The naming scheme for the file name.</param>
        /// <returns></returns>
        private static string BuildOarPath(string regionName, string baseDir, NamingType naming)
        {
            FileInfo path = null;

            switch (naming)
            {
            case NamingType.Overwrite:
                path = new FileInfo(baseDir + Path.DirectorySeparatorChar + regionName + ".oar");
                return(path.FullName);

            case NamingType.Time:
                path =
                    new FileInfo(baseDir + Path.DirectorySeparatorChar + regionName +
                                 GetTimeString() + ".oar");
                return(path.FullName);

            case NamingType.Sequential:
                // All codepaths in GetNextFile should return a file name ending in .oar
                path = new FileInfo(GetNextFile(baseDir, regionName));
                return(path.FullName);

            default:
                m_log.Warn("VERY BAD: Unhandled case element " + naming);
                break;
            }

            return(null);
        }
コード例 #5
0
 private DJson(object data, bool denyGet, bool retain, string[] props, NamingType namingType)
 {
     _data       = data;
     _denyGet    = denyGet;
     _props      = props;
     _retain     = retain;
     _namingType = namingType;
 }
コード例 #6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="data">数据</param>
 /// <param name="namingType">命名方式</param>
 /// <param name="dateTimeFormat">日期格式</param>
 /// <param name="formatting">是否缩进</param>
 /// <param name="behavior">请求方式</param>
 public JsonFormatResult(object data, NamingType namingType, string dateTimeFormat = "yyyy-MM-dd HH:mm:ss", Formatting formatting = Formatting.None, JsonRequestBehavior behavior = JsonRequestBehavior.DenyGet)
 {
     Data                = data;
     NamingType          = namingType;
     DateTimeFormat      = dateTimeFormat;
     Formatting          = formatting;
     JsonRequestBehavior = behavior;
 }
コード例 #7
0
 /// <summary> 构造函数 </summary>
 /// <param name="camelCase">驼峰</param>
 /// <param name="retain">保留/排除:true为保留</param>
 /// <param name="replaceProps">需替换的属性</param>
 /// <param name="props"></param>
 public JsonContractResolver(NamingType camelCase = NamingType.Normal, bool retain = true,
                             IDictionary <string, string> replaceProps = null, params string[] props)
 {
     _replaceProps = replaceProps;
     _camelCase    = camelCase;
     _retain       = retain;
     _props        = props;
 }
コード例 #8
0
ファイル: DJson.cs プロジェクト: shoy160/Shoy.Common
 private DJson(object data, bool denyGet, bool retain, string[] props, NamingType namingType)
 {
     _data = data;
     _denyGet = denyGet;
     _props = props;
     _retain = retain;
     _namingType = namingType;
 }
コード例 #9
0
        /// <summary>
        /// 命名
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="namingType">命名规则</param>
        /// <returns></returns>
        public static string ToNamingCase(this string name, NamingType namingType)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("名称不能为空!", nameof(name));
            }

            if (Whitespace.IsMatch(name))
            {
                throw new ArgumentException($"“{name}”不是一个有效的名称。", nameof(name));
            }

            switch (namingType)
            {
            case NamingType.Normal:
                return(name);

            case NamingType.CamelCase:

                if (char.IsUpper(name[0]))
                {
                    return(name.Substring(0, 1).ToLower() + PatternCamelCase.Replace(name.Substring(1), x =>
                    {
                        return x.Groups["letter"].Value.ToUpper();
                    }));
                }

                return(PatternCamelCase.Replace(name, x =>
                {
                    return x.Groups["letter"].Value.ToUpper();
                }));

            case NamingType.UrlCase:
                return(PatternUrlCamelCase.Replace(name, x =>
                {
                    var match = x.Groups["letter"];
                    var value = match.Value.ToLower();
                    if (match.Index > 0)
                    {
                        value = string.Concat("_", value);
                    }
                    return value;
                }));

            case NamingType.PascalCase:
                return(PatternPascalCase.Replace(name, x =>
                {
                    return x.Groups["letter"].Value.ToUpper();
                }));

            default:
                throw new NotSupportedException();
            }
        }
コード例 #10
0
        private static JsonSerializerSettings LoadSetting(NamingType namingType, bool indented, string[] props,
                                                          bool retain)
        {
            var setting = LoadSetting(namingType, indented);

            if (props != null && props.Length > 0)
            {
                setting.ContractResolver = new JsonContractResolver(namingType, retain, props);
            }
            return(setting);
        }
コード例 #11
0
        public new string ToString()
        {
            string retval = "";

            retval += "[AUTO BACKUP]: AutoBackup: " + (Enabled ? "ENABLED" : "DISABLED") + "\n";
            retval += "[AUTO BACKUP]: Interval: " + IntervalMinutes + " minutes" + "\n";
            retval += "[AUTO BACKUP]: Do Busy Check: " + (BusyCheck ? "Yes" : "No") + "\n";
            retval += "[AUTO BACKUP]: Naming Type: " + NamingType.ToString() + "\n";
            retval += "[AUTO BACKUP]: Backup Dir: " + BackupDir + "\n";
            retval += "[AUTO BACKUP]: Script: " + Script + "\n";
            return(retval);
        }
コード例 #12
0
ファイル: Constants.cs プロジェクト: shoy160/spear-components
        public static string EntityCode(this TableDto table, ProviderType provider,
                                        LanguageType language = LanguageType.CSharp, NamingType type = NamingType.Naming)
        {
            switch (language)
            {
            case LanguageType.CSharp:
                return(table.CSharpEntityCode(provider, type));

            case LanguageType.Java:
                return(table.JavaEntityCode(provider, type));
            }
            return(table.CSharpEntityCode(provider, type));
        }
コード例 #13
0
            public string ComvertName(string originalName)
            {
                NamingType type = this.ParseNamigType();

                if (type != NamingType.Suffix)
                {
                    if (type == NamingType.Swap)
                    {
                        return(this.GetSwapName(originalName));
                    }
                    return(this.name);
                }
                return(originalName + this.GetSffixName());
            }
コード例 #14
0
        private static JsonSerializerSettings LoadSetting(NamingType namingType, bool indented)
        {
            var setting = new JsonSerializerSettings
            {
                ContractResolver = new JsonContractResolver(namingType)
            };

            if (indented)
            {
                setting.Formatting = Formatting.Indented;
            }
            setting.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
            setting.DateFormatString   = DateFormatString;
            return(setting);
        }
コード例 #15
0
        /// <summary> 反序列化json为列表 </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json"></param>
        /// <param name="namingType"></param>
        /// <returns></returns>
        public IEnumerable <T> JsonList <T>(string json, NamingType namingType = NamingType.Normal)
        {
            var serializer = new JsonSerializer();

            if (namingType != NamingType.Normal)
            {
                serializer.ContractResolver = new JsonContractResolver(namingType);
            }
            using (var sr = new StringReader(json))
            {
                using (var jsonReader = new JsonTextReader(sr))
                {
                    var obj = serializer.Deserialize(jsonReader, typeof(IEnumerable <T>));
                    return(obj as IEnumerable <T>);
                }
            }
        }
コード例 #16
0
ファイル: StringExtentions.cs プロジェクト: juszhc/CodeArts
    /// <summary>
    /// 命名。
    /// </summary>
    /// <param name="name">名称。</param>
    /// <param name="namingType">命名规则。</param>
    /// <returns></returns>
    public static string ToNamingCase(this string name, NamingType namingType)
    {
        if (string.IsNullOrEmpty(name))
        {
            throw new ArgumentException("名称不能为空!", nameof(name));
        }

        if (Whitespace.IsMatch(name))
        {
            throw new ArgumentException($"“{name}”不是一个有效的名称。", nameof(name));
        }

        switch (namingType)
        {
        case NamingType.Normal:
            return(name);

        case NamingType.CamelCase:

            if (char.IsUpper(name[0]))
            {
#if NETSTANDARD2_1_OR_GREATER
                string value = name[1..];
コード例 #17
0
 public JsonContractResolver(NamingType camelCase)
 {
     _camelCase = camelCase;
 }
コード例 #18
0
 /// <summary> Json序列化 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="jsonObj"></param>
 /// <param name="namingType">命名规则</param>
 /// <param name="indented">是否缩进</param>
 /// <param name="retain">保留/排除</param>
 /// <param name="props">属性选择</param>
 /// <returns></returns>
 public static string ToJson <T>(T jsonObj, NamingType namingType = NamingType.Normal, bool indented = false,
                                 bool retain = true, params string[] props)
 {
     return(_jsonHelper.ToJson(jsonObj, namingType, indented, retain, props));
 }
コード例 #19
0
 public JsonContractResolver(NamingType camelCase)
 {
     _camelCase = camelCase;
 }
コード例 #20
0
 /// <summary> 序列化为json格式 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="jsonObj"></param>
 /// <param name="namingType">命名规则</param>
 /// <param name="indented">是否缩进</param>
 /// <returns></returns>
 public string ToJson <T>(T jsonObj, NamingType namingType = NamingType.Normal, bool indented = false)
 {
     return(JsonConvert.SerializeObject(jsonObj, LoadSetting(namingType, indented)));
 }
コード例 #21
0
 /// <summary> 序列化为json格式 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="jsonObj"></param>
 /// <param name="namingType">命名规则</param>
 /// <param name="indented">是否缩进</param>
 /// <param name="retain">保留/排除</param>
 /// <param name="props">属性选择</param>
 /// <returns></returns>
 public string ToJson <T>(T jsonObj, NamingType namingType = NamingType.Normal, bool indented = false,
                          bool retain = true, params string[] props)
 {
     return(JsonConvert.SerializeObject(jsonObj, LoadSetting(namingType, indented, props, retain)));
 }
コード例 #22
0
 public JsonContractResolver(NamingType camelCase, IDictionary <string, string> replaceProps = null)
 {
     _camelCase    = camelCase;
     _replaceProps = replaceProps;
 }
コード例 #23
0
 /// <summary> 将json发序列化为对象 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="json"></param>
 /// <param name="namingType"></param>
 /// <returns></returns>
 public T Json <T>(string json, NamingType namingType = NamingType.Normal)
 {
     return(JsonConvert.DeserializeObject <T>(json, LoadSetting(namingType, false)));
 }
コード例 #24
0
 public static DJson Json(object data, bool denyGet = false, bool retain = true, NamingType namingType = NamingType.Normal, params string[] props)
 {
     return(new DJson(data, denyGet, retain, props, namingType));
 }
コード例 #25
0
ファイル: DJson.cs プロジェクト: shoy160/Shoy.Common
 public static DJson Json(object data, bool denyGet = false, bool retain = true, NamingType namingType = NamingType.Normal, params string[] props)
 {
     return new DJson(data, denyGet, retain, props, namingType);
 }
コード例 #26
0
        public static int GetNamePrecedenceRate(this NamingType namingType)
        {
            switch (namingType)
            {
            case NamingType.NONE:
                return(0x7FFFFFFF);

            case NamingType.PLANE:
                return(-0x00000005);

            case NamingType.BLIMP:
                return(0x00000001);

            case NamingType.SHIP:
                return(-0x00000002);

            case NamingType.FERRY:
                return(0x00000001);

            case NamingType.TRAIN:
                return(0x00000003);

            case NamingType.MONORAIL:
                return(0x00000004);

            case NamingType.TRAM:
                return(0x00000006);

            case NamingType.METRO:
                return(0x00000005);

            case NamingType.BUS:
                return(0x00000007);

            case NamingType.TOUR_BUS:
                return(0x00000009);

            case NamingType.MONUMENT:
                return(0x00000005);

            case NamingType.CAMPUS:
                return(0x00000010);

            case NamingType.BEAUTIFICATION:
                return(0x0000000a);

            case NamingType.HEALTHCARE:
                return(0x0000000b);

            case NamingType.POLICEDEPARTMENT:
                return(0x0000000b);

            case NamingType.FIREDEPARTMENT:
                return(0x0000000b);

            case NamingType.EDUCATION:
                return(0x0000000c);

            case NamingType.DISASTER:
                return(0x0000000d);

            case NamingType.GARBAGE:
                return(0x0000000f);

            case NamingType.PARKAREA:
                return(0x00000010);

            case NamingType.DISTRICT:
                return(0x00000010);

            case NamingType.INDUSTRY_AREA:
                return(0x00000010);

            case NamingType.ADDRESS:
                return(0x00000011);

            case NamingType.RICO:
                return(0x000000e);

            case NamingType.CABLE_CAR:
                return(0x00000004);

            case NamingType.TROLLEY:
                return(0x00000006);

            case NamingType.HELICOPTER:
                return(0x00000001);

            case NamingType.TERMINAL:
                return(-0x00000020);

            default:
                return(0x7FFFFFFF);
            }
        }
コード例 #27
0
 /// <summary> Json列表反序列化 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="json"></param>
 /// <param name="namingType"></param>
 /// <returns></returns>
 public static IEnumerable <T> JsonList <T>(string json, NamingType namingType = NamingType.Normal)
 {
     return(_jsonHelper.JsonList <T>(json, namingType));
 }
コード例 #28
0
ファイル: DefaultJsonHelper.cs プロジェクト: juszhc/CodeArts
 /// <summary>
 /// 构造定义命名解析风格。
 /// </summary>
 /// <param name="namingCase">命名规则。</param>
 public JsonContractResolver(NamingType namingCase) => _camelCase = namingCase;
コード例 #29
0
        /// <summary>
        /// Top-level method for creating an absolute path to an OAR backup file based on what naming scheme the user wants.
        /// </summary>
        /// <param name="regionName">Name of the region to save.</param>
        /// <param name="baseDir">Absolute or relative path to the directory where the file should reside.</param>
        /// <param name="naming">The naming scheme for the file name.</param>
        /// <returns></returns>
        private static string BuildOarPath(string regionName, string baseDir, NamingType naming)
        {
            FileInfo path = null;
            switch (naming)
            {
                case NamingType.Overwrite:
                    path = new FileInfo(baseDir + Path.DirectorySeparatorChar + regionName + ".oar");
                    return path.FullName;
                case NamingType.Time:
                    path =
                        new FileInfo(baseDir + Path.DirectorySeparatorChar + regionName +
                                     GetTimeString() + ".oar");
                    return path.FullName;
                case NamingType.Sequential:
                    // All codepaths in GetNextFile should return a file name ending in .oar
                    path = new FileInfo(GetNextFile(baseDir, regionName));
                    return path.FullName;
                default:
                    m_log.Warn("VERY BAD: Unhandled case element " + naming);
                    break;
            }

            return null;
        }
コード例 #30
0
 /// <summary> Json序列化 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="jsonObj"></param>
 /// <param name="namingType">命名规则</param>
 /// <param name="indented">是否缩进</param>
 /// <returns></returns>
 public static string ToJson <T>(T jsonObj, NamingType namingType = NamingType.Normal, bool indented = false)
 {
     return(_jsonHelper.ToJson(jsonObj, namingType, indented));
 }
コード例 #31
0
 public NamingAttribute(NamingType namingType)
 {
     NamingType = namingType;
 }
コード例 #32
0
 /// <summary> Json反序列化 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="json"></param>
 /// <param name="namingType"></param>
 /// <returns></returns>
 public static T Json <T>(string json, NamingType namingType = NamingType.Normal)
 {
     return(_jsonHelper.Json <T>(json, namingType));
 }
コード例 #33
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="namingType">命名方式</param>
 /// <param name="dateTimeFormat">日期格式</param>
 /// <param name="formatting">是否缩进</param>
 public JsonContentNegotiator(NamingType namingType, string dateTimeFormat = "yyyy-MM-dd HH:mm:ss", Formatting formatting = Formatting.None)
 {
     NamingType     = namingType;
     DateTimeFormat = dateTimeFormat;
     Formatting     = formatting;
 }
コード例 #34
0
 /// <summary> 匿名对象反序列化 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="json"></param>
 /// <param name="anonymousTypeObject"></param>
 /// <param name="namingType"></param>
 /// <returns></returns>
 public static T Json <T>(string json, T anonymousTypeObject, NamingType namingType = NamingType.Normal)
 {
     return(_jsonHelper.Json(json, anonymousTypeObject, namingType));
 }
コード例 #35
0
 /// <summary>
 /// 格式化JsonResult(日期,命名方式)配置
 /// </summary>
 /// <param name="config"></param>
 /// <param name="namingType"></param>
 /// <param name="dateTimeFormat"></param>
 /// <param name="formatting"></param>
 public static void Register(HttpConfiguration config, NamingType namingType, string dateTimeFormat = "yyyy-MM-dd HH:mm:ss", Formatting formatting = Formatting.None)
 {
     config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(namingType, dateTimeFormat, formatting));
 }