/// <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; }
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()); }
/// <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); }
private DJson(object data, bool denyGet, bool retain, string[] props, NamingType namingType) { _data = data; _denyGet = denyGet; _props = props; _retain = retain; _namingType = namingType; }
/// <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; }
/// <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; }
/// <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(); } }
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); }
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); }
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)); }
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()); }
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); }
/// <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>); } } }
/// <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..];
public JsonContractResolver(NamingType camelCase) { _camelCase = camelCase; }
/// <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)); }
/// <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))); }
/// <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))); }
public JsonContractResolver(NamingType camelCase, IDictionary <string, string> replaceProps = null) { _camelCase = camelCase; _replaceProps = replaceProps; }
/// <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))); }
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)); }
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); }
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); } }
/// <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)); }
/// <summary> /// 构造定义命名解析风格。 /// </summary> /// <param name="namingCase">命名规则。</param> public JsonContractResolver(NamingType namingCase) => _camelCase = namingCase;
/// <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; }
/// <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)); }
public NamingAttribute(NamingType namingType) { NamingType = namingType; }
/// <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)); }
/// <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; }
/// <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)); }
/// <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)); }