123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
-
- using System;
- namespace WingCloudServer.GeneralDocTools.Helper
- {
- /// <summary>
- /// 通用帮助类
- /// </summary>
- public class CommonHelper
- {
- public static string EnumApiString = "枚举代码";
- public static string NotificationApiString = "通知服务";
- /// <summary>
- /// 根据输入的字符串判断类型
- /// </summary>
- /// <returns></returns>
- public static string GetJsonDataTypeByString(string typeStr)
- {
- var enumStr = "";
- string result;
- //if (typeStr.Contains("AccountString") || typeStr.Contains("BaseParamsString") || typeStr.Contains("BaseString") || typeStr.Contains("EmailString")
- // || typeStr.Contains("PasswordString") || typeStr.Contains("PhoneString") || typeStr.Contains("UrlString") || typeStr.Contains("VerificationCode"))
- //{
- // typeStr = "System.String";
- //} else
- if (typeStr.Contains("WingInterfaceLibrary") && typeStr.Contains("`1"))
- {
- typeStr = "Object";
- }
- else if (typeStr.Contains("`1"))
- {
- typeStr = "`1";
- }
- else if (typeStr.Contains("[]") && typeStr != "Byte[]")
- {
- typeStr = "[]";
- }
- else if (typeStr.Contains("Enum"))
- {
- enumStr = typeStr;
- typeStr = "Enum";
- }
- else if (typeStr == "LiveConsultationMemberStatus")
- {
- enumStr = typeStr;
- typeStr = "Enum";
- }
- switch (typeStr)
- {
- case "Enum":
- result = enumStr;
- break;
- case "Int32":
- result = "Integer";
- break;
- case "System.Int32":
- result = "Integer";
- break;
- case "Dictionary`2":
- result = "Object";
- break;
- case "Stream":
- case "Byte[]":
- result = "File";
- break;
- case "`1":
- case "[]":
- result = "Array";
- break;
- case "String":
- case "System.String":
- result = "String";
- break;
- case "Decimal":
- case "Long":
- case "Int16":
- case "Int64":
- case "System.Decimal":
- case "System.Int16":
- case "System.Long":
- case "System.Int64":
- result = "Number";
- break;
- case "Float":
- case "System.Float":
- result = "Float";
- break;
- case "Double":
- case "System.Double":
- result = "Double";
- break;
- case "DateTime":
- case "System.DateTime":
- result = "DateTime";
- break;
- case "Boolean":
- case "System.Boolean":
- result = "Boolean";
- break;
- default:
- result = "Object";
- break;
- }
- return result;
- }
- /// <summary>
- /// 计算字符串中子串出现的次数
- /// </summary>
- /// <param name="str">字符串</param>
- /// <param name="substring">子串</param>
- /// <returns>出现的次数</returns>
- public static int SubstringCount(string str, string substring)
- {
- if (str.Contains(substring))
- {
- string strReplaced = str.Replace(substring, "");
- return (str.Length - strReplaced.Length) / substring.Length;
- }
- return 0;
- }
- /// <summary>
- /// 当前时间转long时间戳
- /// </summary>
- /// <returns></returns>
- public static long DateTimeToUnixTime()
- {
- return (long)(DateTime.Now - TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0), TimeZoneInfo.Local)).TotalMilliseconds;
- }
- /// <summary>
- /// 获取特殊的目标值
- /// </summary>
- /// <returns></returns>
- public static long GetSpecicalTargetIndex()
- {
- System.Threading.Thread.Sleep(1);
- long value = 1;
- for (int i = 0; i < 5; i++)
- {
- Random r = new Random();
- value = value * r.Next(10, 20);
- }
- long val = DateTimeToUnixTime() + value;
- return val;
- }
- }
- }
|