using System;

namespace Core.Util
{
    /// <summary>
    ///GUID helper classes
    /// </summary>
    public static class GuidHelper
    {
        /// <summary>
        ///To generate a primary key
        /// </summary>
        /// <returns></returns>
        public static string GenerateKey()
        {
        	//ToSequentialGuid() is an extension method
            returnGuid.NewGuid().ToSequentialGuid().ToUpper(); }}}Copy the code

ToSequentialGuid() is the extension method

using System;

namespace Core.Util
{
    public static partial class Extention
    {
        /// <summary>
        ///Convert to an ordered GUID
        ///Note: Contains 50 characters
        /// </summary>
        /// <param name="guid">A new GUID</param>
        /// <returns></returns>
        public static string ToSequentialGuid(this Guid guid)
        {
            var timeStr = (DateTime.Now.ToCstTime().Ticks / 10000).ToString("x8");
            var newGuid = $"{timeStr.PadLeft(13.'0')}-{guid}";

            returnnewGuid; }}}Copy the code