mirror of
https://gitee.com/microi-net/Dos.Common.git
synced 2025-12-06 10:49:08 +08:00
v1.0.8.8
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Dos.Common
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
return str.Trim() ?? null;
|
||||
return str.Trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -30,13 +30,36 @@ namespace Dos.Common
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DosIsNullOrWhiteSpace(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="trimChars"></param>
|
||||
/// <returns></returns>
|
||||
public static string DosTrim(this string str, params char[] trimChars)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
return str.Trim(trimChars) ?? null;
|
||||
return str.Trim(trimChars);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="trimChars"></param>
|
||||
/// <returns></returns>
|
||||
public static string DosReplace(this string str, string str1, string str2)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
return str.Replace(str1, str2);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -50,7 +73,7 @@ namespace Dos.Common
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
return str.TrimStart(trimChars) ?? null;
|
||||
return str.TrimStart(trimChars);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -64,7 +87,7 @@ namespace Dos.Common
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
return str.TrimEnd(trimChars) ?? null;
|
||||
return str.TrimEnd(trimChars);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -128,7 +151,7 @@ namespace Dos.Common
|
||||
/// </summary>
|
||||
/// <param name="ip"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DosIsIP(this string ip)
|
||||
public static bool DosIsIp(this string ip)
|
||||
{
|
||||
return RegexHelper.IsIP(ip);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Dos.Common.Helper;
|
||||
|
||||
namespace Dos.Common
|
||||
{
|
||||
@@ -25,6 +27,22 @@ namespace Dos.Common
|
||||
/// </summary>
|
||||
public class CommonHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取当前项目完整路径,如D:\Web\
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetFullPath()
|
||||
{
|
||||
if (HttpContext.Current != null)
|
||||
{
|
||||
return HttpContext.Current.Server.MapPath("~/");
|
||||
}
|
||||
if (!AppDomain.CurrentDomain.BaseDirectory.DosIsNullOrWhiteSpace())
|
||||
{
|
||||
return AppDomain.CurrentDomain.BaseDirectory;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
#region 取首字母
|
||||
/// <summary>
|
||||
/// 获取汉字首字母(可包含多个汉字)
|
||||
@@ -33,36 +51,12 @@ namespace Dos.Common
|
||||
/// <returns></returns>
|
||||
public static string GetChineseSpell(string strText)
|
||||
{
|
||||
int len = strText.Length;
|
||||
string myStr = "";
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
myStr += GetSpell(strText.Substring(i, 1));
|
||||
}
|
||||
return myStr;
|
||||
return StringHelper.GetChineseSpell(strText);
|
||||
}
|
||||
|
||||
public static string GetSpell(string cnChar)
|
||||
{
|
||||
var arrCn = Encoding.Default.GetBytes(cnChar);
|
||||
if (arrCn.Length > 1)
|
||||
{
|
||||
int area = (short)arrCn[0];
|
||||
int pos = (short)arrCn[1];
|
||||
int code = (area << 8) + pos;
|
||||
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
|
||||
for (int i = 0; i < 26; i++)
|
||||
{
|
||||
int max = 55290;
|
||||
if (i != 25) max = areacode[i + 1];
|
||||
if (areacode[i] <= code && code < max)
|
||||
{
|
||||
return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
|
||||
}
|
||||
}
|
||||
return "*";
|
||||
}
|
||||
return cnChar;
|
||||
return StringHelper.GetSpell(cnChar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,115 +66,23 @@ namespace Dos.Common
|
||||
/// <returns></returns>
|
||||
public static string GetInitial(string c)
|
||||
{
|
||||
byte[] array = new byte[2];
|
||||
array = System.Text.Encoding.Default.GetBytes(c);
|
||||
int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
|
||||
if (i < 0xB0A1) return "*";
|
||||
if (i < 0xB0C5) return "A";
|
||||
if (i < 0xB2C1) return "B";
|
||||
if (i < 0xB4EE) return "C";
|
||||
if (i < 0xB6EA) return "D";
|
||||
if (i < 0xB7A2) return "E";
|
||||
if (i < 0xB8C1) return "F";
|
||||
if (i < 0xB9FE) return "G";
|
||||
if (i < 0xBBF7) return "H";
|
||||
if (i < 0xBFA6) return "J";
|
||||
if (i < 0xC0AC) return "K";
|
||||
if (i < 0xC2E8) return "L";
|
||||
if (i < 0xC4C3) return "M";
|
||||
if (i < 0xC5B6) return "N";
|
||||
if (i < 0xC5BE) return "O";
|
||||
if (i < 0xC6DA) return "P";
|
||||
if (i < 0xC8BB) return "Q";
|
||||
if (i < 0xC8F6) return "R";
|
||||
if (i < 0xCBFA) return "S";
|
||||
if (i < 0xCDDA) return "T";
|
||||
if (i < 0xCEF4) return "W";
|
||||
if (i < 0xD1B9) return "X";
|
||||
if (i < 0xD4D1) return "Y";
|
||||
if (i < 0xD7FA) return "Z";
|
||||
return "*";
|
||||
return StringHelper.GetInitial(c);
|
||||
}
|
||||
#endregion
|
||||
#region 计算匹配率/相似度
|
||||
/// <summary>
|
||||
/// 计算相似度。
|
||||
/// </summary>
|
||||
public static SimilarityResult SimilarityRate(string str1, string str2)
|
||||
public static StringHelper.SimilarityResult SimilarityRate(string str1, string str2)
|
||||
{
|
||||
var result = new SimilarityResult();
|
||||
var arrChar1 = str1.ToCharArray();
|
||||
var arrChar2 = str2.ToCharArray();
|
||||
var computeTimes = 0;
|
||||
var row = arrChar1.Length + 1;
|
||||
var column = arrChar2.Length + 1;
|
||||
var matrix = new int[row, column];
|
||||
//开始时间
|
||||
var beginTime = DateTime.Now;
|
||||
//初始化矩阵的第一行和第一列
|
||||
for (var i = 0; i < column; i++)
|
||||
{
|
||||
matrix[0, i] = i;
|
||||
}
|
||||
for (var i = 0; i < row; i++)
|
||||
{
|
||||
matrix[i, 0] = i;
|
||||
}
|
||||
for (var i = 1; i < row; i++)
|
||||
{
|
||||
for (var j = 1; j < column; j++)
|
||||
{
|
||||
var intCost = 0;
|
||||
intCost = arrChar1[i - 1] == arrChar2[j - 1] ? 0 : 1;
|
||||
//关键步骤,计算当前位置值为左边+1、上面+1、左上角+intCost中的最小值
|
||||
//循环遍历到最后_Matrix[_Row - 1, _Column - 1]即为两个字符串的距离
|
||||
matrix[i, j] = Minimum(matrix[i - 1, j] + 1, matrix[i, j - 1] + 1, matrix[i - 1, j - 1] + intCost);
|
||||
computeTimes++;
|
||||
}
|
||||
}
|
||||
//结束时间
|
||||
var endTime = DateTime.Now;
|
||||
//相似率 移动次数小于最长的字符串长度的20%算同一题
|
||||
var intLength = row > column ? row : column;
|
||||
//_Result.Rate = (1 - (double)_Matrix[_Row - 1, _Column - 1] / intLength).ToString().Substring(0, 6);
|
||||
result.Rate = (1 - (double)matrix[row - 1, column - 1] / (intLength - 1));
|
||||
result.ExeTime = (endTime - beginTime).TotalMilliseconds;
|
||||
result.ComputeTimes = computeTimes.ToString() + " 距离为:" + matrix[row - 1, column - 1].ToString();
|
||||
return result;
|
||||
return StringHelper.SimilarityRate(str1, str2);
|
||||
}
|
||||
/// <summary>
|
||||
/// 取三个数中的最小值
|
||||
/// </summary>
|
||||
private static int Minimum(int first, int second, int third)
|
||||
public static int Minimum(int first, int second, int third)
|
||||
{
|
||||
var intMin = first;
|
||||
if (second < intMin)
|
||||
{
|
||||
intMin = second;
|
||||
}
|
||||
if (third < intMin)
|
||||
{
|
||||
intMin = third;
|
||||
}
|
||||
return intMin;
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算结果
|
||||
/// </summary>
|
||||
public struct SimilarityResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 相似度,0.54即54%。
|
||||
/// </summary>
|
||||
public double Rate;
|
||||
/// <summary>
|
||||
/// 对比次数
|
||||
/// </summary>
|
||||
public string ComputeTimes;
|
||||
/// <summary>
|
||||
/// 执行时间,毫秒
|
||||
/// </summary>
|
||||
public double ExeTime;
|
||||
return StringHelper.Minimum(first, second,third);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
22
Common/EnumHelper.cs
Normal file
22
Common/EnumHelper.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Dos.Common
|
||||
{
|
||||
public class EnumHelper
|
||||
{
|
||||
public enum HttpParamType
|
||||
{
|
||||
/// <summary>
|
||||
/// json数据。默认值。
|
||||
/// </summary>
|
||||
Json,
|
||||
/// <summary>
|
||||
/// 形如:key=value&key=value&key=value
|
||||
/// </summary>
|
||||
Form
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\Dos.Common.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@@ -50,6 +51,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Common\CommonExpand.cs" />
|
||||
<Compile Include="Common\CommonHelper.cs" />
|
||||
<Compile Include="Common\EnumHelper.cs" />
|
||||
<Compile Include="Common\Types.cs" />
|
||||
<Compile Include="EmitMapper\AST\CompilationContext.cs" />
|
||||
<Compile Include="EmitMapper\AST\Helpers\AstBuildHelper.cs" />
|
||||
@@ -167,15 +169,6 @@
|
||||
<Compile Include="EmitMapper\Utils\ReflectionUtils.cs" />
|
||||
<Compile Include="EmitMapper\Utils\ThreadSaveCache.cs" />
|
||||
<Compile Include="Helper\StringHelper.cs" />
|
||||
<Compile Include="JsonHelper\dynamic.cs" />
|
||||
<Compile Include="JsonHelper\Formatter.cs" />
|
||||
<Compile Include="JsonHelper\Getters.cs" />
|
||||
<Compile Include="JsonHelper\JSON.cs" />
|
||||
<Compile Include="JsonHelper\JsonParser.cs" />
|
||||
<Compile Include="JsonHelper\JsonProp.cs" />
|
||||
<Compile Include="JsonHelper\JsonSerializer.cs" />
|
||||
<Compile Include="JsonHelper\Reflection.cs" />
|
||||
<Compile Include="JsonHelper\SafeDictionary.cs" />
|
||||
<Compile Include="Helper\CacheHelper.cs" />
|
||||
<Compile Include="Helper\CmdHelper.cs" />
|
||||
<Compile Include="Helper\ConvertHelper.cs" />
|
||||
@@ -189,6 +182,15 @@
|
||||
<Compile Include="Helper\MsmqHelper.cs" />
|
||||
<Compile Include="Helper\RegexHelper.cs" />
|
||||
<Compile Include="Helper\ImageHelper.cs" />
|
||||
<Compile Include="JsonHelper\dynamic.cs" />
|
||||
<Compile Include="JsonHelper\Formatter.cs" />
|
||||
<Compile Include="JsonHelper\Getters.cs" />
|
||||
<Compile Include="JsonHelper\JSON.cs" />
|
||||
<Compile Include="JsonHelper\JsonParser.cs" />
|
||||
<Compile Include="JsonHelper\JsonProp.cs" />
|
||||
<Compile Include="JsonHelper\JsonSerializer.cs" />
|
||||
<Compile Include="JsonHelper\Reflection.cs" />
|
||||
<Compile Include="JsonHelper\SafeDictionary.cs" />
|
||||
<Compile Include="Model\AccountInfo.cs" />
|
||||
<Compile Include="Model\BaseResult.cs" />
|
||||
<Compile Include="Helper\EmailHelper.cs" />
|
||||
|
||||
@@ -1,8 +1,21 @@
|
||||
未来版本预告:
|
||||
*)
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------*/
|
||||
2016-05-24 Dos.Common(v1.0.8.4)
|
||||
*)去掉一些.net4.0不支持的语法。
|
||||
2016-06-21 Dos.Common(v1.0.8.8)
|
||||
*)增加DateFormatString、UseStrictIsoDate、UseFalseLiteral配置,可以在序列化的时候指定日期格式化方式等。
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------*/
|
||||
2016-06-16 Dos.Common(v1.0.8.7)
|
||||
*)CommonExpand.cs增加扩展。
|
||||
*)优化HttpHelper.cs。现在可以传入ParamType=EnumHelper.HttpParamType.Form参数,使new {key = value} 自动转换成"key=value"形式。
|
||||
*)修复fastJSON反序列化Dictionary<string,string>时,int值转string时为null的Bug。
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------*/
|
||||
2016-06-01 Dos.Common(v1.0.8.5)
|
||||
*)StringHelper.cs增加扩展。
|
||||
*)CommonExpand.cs增加扩展。
|
||||
*)去掉.net4.0不支持的语法。
|
||||
*)增加fastJSON序列化DataTable时DataTableToGeneralJson=true的配置,false时与之前一样,默认为true时,与Json.Net序列化的结果一致。并且增加支持反序列化为DataTable类型。
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------*/
|
||||
|
||||
@@ -12,9 +12,9 @@ namespace Dos.Common
|
||||
public class FileHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 从文件中读取所有内容。(如果文件不存在,返回空字符串)
|
||||
/// 从文件中读取所有内容。(如果文件不存在,返回空字符串)。
|
||||
///<para>filePath:完整路径,如D:\Temp\Temp.json</para>
|
||||
/// </summary>
|
||||
/// <Param name="filePath">完整路径,如D:\Temp\Temp.json</Param>
|
||||
/// <returns></returns>
|
||||
public static string Read(string filePath, Encoding encoding = null)
|
||||
{
|
||||
@@ -36,6 +36,10 @@ namespace Dos.Common
|
||||
/// <returns></returns>
|
||||
public static bool Write(string filePath, string content, Encoding encoding = null)
|
||||
{
|
||||
if (filePath.StartsWith("~") || filePath.StartsWith("/"))
|
||||
{
|
||||
//filePath = AppDomain.CurrentDomain.RelativeSearchPath
|
||||
}
|
||||
File.Delete(filePath);
|
||||
using (var fs = new FileStream(filePath, FileMode.Append, FileAccess.Write))
|
||||
{
|
||||
|
||||
@@ -208,6 +208,11 @@ namespace Dos.Common
|
||||
{
|
||||
postParamString = param.PostParam.ToString();
|
||||
}
|
||||
else if (param.ParamType == EnumHelper.HttpParamType.Form)
|
||||
{
|
||||
var dicParam = JSON.ToObject<Dictionary<string,string>>(JSON.ToJSON(param.PostParam));
|
||||
postParamString = dicParam.Aggregate(postParamString, (current, dic) => current + (dic.Key + "=" + dic.Value + "&")).TrimEnd('&');
|
||||
}
|
||||
else
|
||||
{
|
||||
postParamString = JSON.ToJSON(param.PostParam);
|
||||
|
||||
@@ -70,5 +70,163 @@ namespace Dos.Common.Helper
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#region 取首字母
|
||||
/// <summary>
|
||||
/// 获取汉字首字母(可包含多个汉字)
|
||||
/// </summary>
|
||||
/// <Param name="strText"></Param>
|
||||
/// <returns></returns>
|
||||
public static string GetChineseSpell(string strText)
|
||||
{
|
||||
int len = strText.Length;
|
||||
string myStr = "";
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
myStr += GetSpell(strText.Substring(i, 1));
|
||||
}
|
||||
return myStr;
|
||||
}
|
||||
|
||||
public static string GetSpell(string cnChar)
|
||||
{
|
||||
var arrCn = Encoding.Default.GetBytes(cnChar);
|
||||
if (arrCn.Length > 1)
|
||||
{
|
||||
int area = (short)arrCn[0];
|
||||
int pos = (short)arrCn[1];
|
||||
int code = (area << 8) + pos;
|
||||
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
|
||||
for (int i = 0; i < 26; i++)
|
||||
{
|
||||
int max = 55290;
|
||||
if (i != 25) max = areacode[i + 1];
|
||||
if (areacode[i] <= code && code < max)
|
||||
{
|
||||
return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
|
||||
}
|
||||
}
|
||||
return "*";
|
||||
}
|
||||
return cnChar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取第一个汉字的首字母,只能输入汉字
|
||||
/// </summary>
|
||||
/// <Param name="c"></Param>
|
||||
/// <returns></returns>
|
||||
public static string GetInitial(string c)
|
||||
{
|
||||
byte[] array = new byte[2];
|
||||
array = System.Text.Encoding.Default.GetBytes(c);
|
||||
int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
|
||||
if (i < 0xB0A1) return "*";
|
||||
if (i < 0xB0C5) return "A";
|
||||
if (i < 0xB2C1) return "B";
|
||||
if (i < 0xB4EE) return "C";
|
||||
if (i < 0xB6EA) return "D";
|
||||
if (i < 0xB7A2) return "E";
|
||||
if (i < 0xB8C1) return "F";
|
||||
if (i < 0xB9FE) return "G";
|
||||
if (i < 0xBBF7) return "H";
|
||||
if (i < 0xBFA6) return "J";
|
||||
if (i < 0xC0AC) return "K";
|
||||
if (i < 0xC2E8) return "L";
|
||||
if (i < 0xC4C3) return "M";
|
||||
if (i < 0xC5B6) return "N";
|
||||
if (i < 0xC5BE) return "O";
|
||||
if (i < 0xC6DA) return "P";
|
||||
if (i < 0xC8BB) return "Q";
|
||||
if (i < 0xC8F6) return "R";
|
||||
if (i < 0xCBFA) return "S";
|
||||
if (i < 0xCDDA) return "T";
|
||||
if (i < 0xCEF4) return "W";
|
||||
if (i < 0xD1B9) return "X";
|
||||
if (i < 0xD4D1) return "Y";
|
||||
if (i < 0xD7FA) return "Z";
|
||||
return "*";
|
||||
}
|
||||
#endregion
|
||||
#region 计算匹配率/相似度
|
||||
/// <summary>
|
||||
/// 计算相似度。
|
||||
/// </summary>
|
||||
public static SimilarityResult SimilarityRate(string str1, string str2)
|
||||
{
|
||||
var result = new SimilarityResult();
|
||||
var arrChar1 = str1.ToCharArray();
|
||||
var arrChar2 = str2.ToCharArray();
|
||||
var computeTimes = 0;
|
||||
var row = arrChar1.Length + 1;
|
||||
var column = arrChar2.Length + 1;
|
||||
var matrix = new int[row, column];
|
||||
//开始时间
|
||||
var beginTime = DateTime.Now;
|
||||
//初始化矩阵的第一行和第一列
|
||||
for (var i = 0; i < column; i++)
|
||||
{
|
||||
matrix[0, i] = i;
|
||||
}
|
||||
for (var i = 0; i < row; i++)
|
||||
{
|
||||
matrix[i, 0] = i;
|
||||
}
|
||||
for (var i = 1; i < row; i++)
|
||||
{
|
||||
for (var j = 1; j < column; j++)
|
||||
{
|
||||
var intCost = 0;
|
||||
intCost = arrChar1[i - 1] == arrChar2[j - 1] ? 0 : 1;
|
||||
//关键步骤,计算当前位置值为左边+1、上面+1、左上角+intCost中的最小值
|
||||
//循环遍历到最后_Matrix[_Row - 1, _Column - 1]即为两个字符串的距离
|
||||
matrix[i, j] = Minimum(matrix[i - 1, j] + 1, matrix[i, j - 1] + 1, matrix[i - 1, j - 1] + intCost);
|
||||
computeTimes++;
|
||||
}
|
||||
}
|
||||
//结束时间
|
||||
var endTime = DateTime.Now;
|
||||
//相似率 移动次数小于最长的字符串长度的20%算同一题
|
||||
var intLength = row > column ? row : column;
|
||||
//_Result.Rate = (1 - (double)_Matrix[_Row - 1, _Column - 1] / intLength).ToString().Substring(0, 6);
|
||||
result.Rate = (1 - (double)matrix[row - 1, column - 1] / (intLength - 1));
|
||||
result.ExeTime = (endTime - beginTime).TotalMilliseconds;
|
||||
result.ComputeTimes = computeTimes.ToString() + " 距离为:" + matrix[row - 1, column - 1].ToString();
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 取三个数中的最小值
|
||||
/// </summary>
|
||||
public static int Minimum(int first, int second, int third)
|
||||
{
|
||||
var intMin = first;
|
||||
if (second < intMin)
|
||||
{
|
||||
intMin = second;
|
||||
}
|
||||
if (third < intMin)
|
||||
{
|
||||
intMin = third;
|
||||
}
|
||||
return intMin;
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算结果
|
||||
/// </summary>
|
||||
public struct SimilarityResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 相似度,0.54即54%。
|
||||
/// </summary>
|
||||
public double Rate;
|
||||
/// <summary>
|
||||
/// 对比次数
|
||||
/// </summary>
|
||||
public string ComputeTimes;
|
||||
/// <summary>
|
||||
/// 执行时间,毫秒
|
||||
/// </summary>
|
||||
public double ExeTime;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,18 @@ namespace Dos.Common
|
||||
/// </summary>
|
||||
public bool SerializeNullValues = true;
|
||||
/// <summary>
|
||||
/// 是否采用严格的ISO日期 (default = false) by itdos.com
|
||||
/// </summary>
|
||||
public bool UseStrictIsoDate = false;
|
||||
/// <summary>
|
||||
/// 日期格式化 (default = "yyyy-MM-dd HH:mm:ss") by itdos.com
|
||||
/// </summary>
|
||||
public string DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
/// <summary>
|
||||
/// IsLiteral=false时是否序列化。(default = false)
|
||||
/// </summary>
|
||||
public bool UseFalseLiteral = false;
|
||||
/// <summary>
|
||||
/// Use the UTC date format (default = True)
|
||||
/// </summary>
|
||||
public bool UseUTCDateTime = false;
|
||||
@@ -75,7 +87,7 @@ namespace Dos.Common
|
||||
/// </summary>
|
||||
public bool ParametricConstructorOverride = false;
|
||||
/// <summary>
|
||||
/// Serialize DateTime milliseconds i.e. yyyy-MM-dd HH:mm:ss.nnn (default = false)
|
||||
/// 是否序列化DateTime毫秒。 yyyy-MM-dd HH:mm:ss.nnn (default = false)
|
||||
/// </summary>
|
||||
public bool DateTimeMilliseconds = false;
|
||||
/// <summary>
|
||||
@@ -426,7 +438,7 @@ namespace Dos.Common
|
||||
return isNullOrWhiteSpace ? (object)null : long.Parse(value.ToString());
|
||||
|
||||
else if (conversionType == typeof(string))
|
||||
return isNullOrWhiteSpace ? null : value as string;//by itdos.com 2016-05-09
|
||||
return isNullOrWhiteSpace ? null : value.ToString();//by itdos.com 2016-05-09
|
||||
#endregion
|
||||
|
||||
else if (conversionType.IsEnum)
|
||||
|
||||
@@ -211,24 +211,33 @@ namespace Dos.Common
|
||||
dt = dateTime.ToUniversalTime();
|
||||
|
||||
_output.Append('\"');
|
||||
_output.Append(dt.Year.ToString("0000", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append('-');
|
||||
_output.Append(dt.Month.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append('-');
|
||||
_output.Append(dt.Day.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append('T'); // strict ISO date compliance
|
||||
_output.Append(dt.Hour.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append(':');
|
||||
_output.Append(dt.Minute.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append(':');
|
||||
_output.Append(dt.Second.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
if (_params.DateTimeMilliseconds)
|
||||
|
||||
if (_params.UseStrictIsoDate)
|
||||
{
|
||||
_output.Append('.');
|
||||
_output.Append(dt.Millisecond.ToString("000", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append(dt.Year.ToString("0000", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append('-');
|
||||
_output.Append(dt.Month.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append('-');
|
||||
_output.Append(dt.Day.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append('T'); // strict ISO date compliance
|
||||
_output.Append(dt.Hour.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append(':');
|
||||
_output.Append(dt.Minute.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
_output.Append(':');
|
||||
_output.Append(dt.Second.ToString("00", NumberFormatInfo.InvariantInfo));
|
||||
if (_params.DateTimeMilliseconds)
|
||||
{
|
||||
_output.Append('.');
|
||||
_output.Append(dt.Millisecond.ToString("000", NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
if (_params.UseUTCDateTime)
|
||||
_output.Append('Z');
|
||||
}
|
||||
if (_params.UseUTCDateTime)
|
||||
_output.Append('Z');
|
||||
else
|
||||
{
|
||||
_output.Append(dt.ToString(_params.DateFormatString));
|
||||
}
|
||||
|
||||
|
||||
_output.Append('\"');
|
||||
}
|
||||
@@ -426,7 +435,7 @@ namespace Dos.Common
|
||||
append = true;
|
||||
}
|
||||
|
||||
Getters[] g = Reflection.Instance.GetGetters(t, _params.ShowReadOnlyProperties, _params.IgnoreAttributes);
|
||||
Getters[] g = Reflection.Instance.GetGetters(t, _params.ShowReadOnlyProperties, _params.IgnoreAttributes, _params.UseFalseLiteral);
|
||||
int c = g.Length;
|
||||
for (int ii = 0; ii < c; ii++)
|
||||
{
|
||||
|
||||
@@ -507,7 +507,7 @@ namespace Dos.Common
|
||||
return (GenericGetter)getter.CreateDelegate(typeof(GenericGetter));
|
||||
}
|
||||
|
||||
internal Getters[] GetGetters(Type type, bool ShowReadOnlyProperties, List<Type> IgnoreAttributes)//JSONParameters param)
|
||||
internal Getters[] GetGetters(Type type, bool ShowReadOnlyProperties, List<Type> IgnoreAttributes,bool UseFalseLiteral)//JSONParameters param)
|
||||
{
|
||||
Getters[] val = null;
|
||||
if (_getterscache.TryGetValue(type, out val))
|
||||
@@ -568,7 +568,7 @@ namespace Dos.Common
|
||||
if (found)
|
||||
continue;
|
||||
}
|
||||
if (f.IsLiteral == false)
|
||||
if (f.IsLiteral == false && UseFalseLiteral)
|
||||
{
|
||||
GenericGetter g = CreateGetField(type, f);
|
||||
if (g != null)
|
||||
|
||||
@@ -37,10 +37,14 @@ namespace Dos.Common
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
/// <summary>
|
||||
/// 参数类型。可选:Json、Form。默认Json。传入Form则会将new { Key1 = Value1, Key2 = Value2}转换成"key1=value1&key2=value2"形式。
|
||||
/// </summary>
|
||||
public EnumHelper.HttpParamType ParamType { get; set; }
|
||||
/// <summary>
|
||||
/// Post参数。
|
||||
/// <para>可以传入Json对像:new { Key1 = Value1, Key2 = Value2}</para>
|
||||
/// <para>可以传入Json字符串:{"Key1":"Value1","Key2":"Value2"}</para>
|
||||
/// <para>可以传入key/value字符串:"ke=value&key=value"</para>
|
||||
/// <para>可以传入key/value字符串:"key1=value1&key2=value2"</para>
|
||||
/// <para>可以传入xml字符串等等</para>
|
||||
/// </summary>
|
||||
public object PostParam { get; set; }
|
||||
@@ -50,7 +54,7 @@ namespace Dos.Common
|
||||
/// <para>可以传入Json字符串:{"Key1":"Value1","Key2":"Value2"}</para>
|
||||
/// </summary>
|
||||
public object GetParam { get; set; }
|
||||
|
||||
|
||||
private int _timeOut = 5;
|
||||
/// <summary>
|
||||
/// 请求超时时间。单位:秒。默认值5秒。
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("Dos.Common")]
|
||||
[assembly: AssemblyCompany("ITdos.com")]
|
||||
[assembly: AssemblyProduct("Dos.Common")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2009-2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@@ -32,6 +32,6 @@ using System.Runtime.InteropServices;
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.8.4")]
|
||||
[assembly: AssemblyFileVersion("1.0.8.4")]
|
||||
[assembly: AssemblyVersion("1.0.8.8")]
|
||||
[assembly: AssemblyFileVersion("1.0.8.8")]
|
||||
[assembly: InternalsVisibleTo("EmitMapperAssembly")]
|
||||
@@ -1,4 +1,10 @@
|
||||
2016-05-18
|
||||
2016-06-21
|
||||
*)增加DateFormatString、UseStrictIsoDate、UseFalseLiteral配置,可以在序列化的时候指定日期格式化方式等。
|
||||
|
||||
2016-06-14
|
||||
*)修复fastJSON反序列化Dictionary<string,string>时,int值转string时为null的Bug。
|
||||
|
||||
2016-05-18
|
||||
*)增加fastJSON序列化DataTable时DataTableToGeneralJson=true的配置,false时与之前一样,默认为true时,与Json.Net序列化的结果一致。并且增加支持反序列化为DataTable类型。
|
||||
|
||||
2016-05-12
|
||||
|
||||
Reference in New Issue
Block a user