| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- /*-------------------------------------------------------------------------
- * 功能描述:NumberGenerater
- * 作者:xulisong
- * 创建时间: 2019/2/13 17:31:00
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SAGA.DotNetUtils.Data
- {
- /// <summary>
- /// 序号生成器
- /// </summary>
- public class NumberGenerater
- {
- private const string DefaultCategory = "D39D59D2-A068-4366-B915-CA651698E30A";
- private Dictionary<string, int> m_Seeds;
- public NumberGenerater()
- {
- m_Seeds = new Dictionary<string, int>();
- }
- public string GetNumber(string category, string format)
- {
- if (!m_Seeds.TryGetValue(category, out int seed))
- {
- m_Seeds[category] = seed;
- }
- return string.Format(format, ++seed);
- }
-
- public string GetNumber(string format)
- {
- return GetNumber(DefaultCategory, format);
- }
- public string GetNumberWithPrefix(string category, string prefix)
- {
- if (!m_Seeds.TryGetValue(category, out int seed))
- {
- m_Seeds[category] = seed;
- }
- return string.Format("{0}{1}", prefix, ++seed);
- }
- public string GetNumberWithPrefix(string prefix)
- {
- return GetNumberWithPrefix(DefaultCategory, prefix);
- }
- }
- }
|