2020-05-07 11:45:28 +02:00
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace zero.Core.Utils
|
|
|
|
|
{
|
|
|
|
|
public class IdGenerator
|
|
|
|
|
{
|
2021-03-18 13:58:26 +01:00
|
|
|
public static string Classic()
|
|
|
|
|
{
|
|
|
|
|
return Guid.NewGuid().ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 11:45:28 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new unique Id
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string Create(int length = -1)
|
|
|
|
|
{
|
2021-03-17 14:49:10 +01:00
|
|
|
if (length < 1)
|
2020-05-07 11:45:28 +02:00
|
|
|
{
|
2021-03-17 14:49:10 +01:00
|
|
|
length = 12;
|
|
|
|
|
}
|
|
|
|
|
//if (length > 0)
|
|
|
|
|
//{
|
2020-05-07 11:45:28 +02:00
|
|
|
return Convert.ToBase64String(Guid.NewGuid().ToByteArray())
|
|
|
|
|
.Replace("/", String.Empty)
|
|
|
|
|
.Replace("+", String.Empty)
|
|
|
|
|
.Replace("-", String.Empty)
|
|
|
|
|
.ToLowerInvariant()
|
|
|
|
|
.Substring(0, length);
|
2021-03-17 14:49:10 +01:00
|
|
|
//}
|
2020-05-07 11:45:28 +02:00
|
|
|
|
2021-03-17 14:49:10 +01:00
|
|
|
//return Guid.NewGuid().ToString();
|
2020-05-07 11:45:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|