Skip to content

Instantly share code, notes, and snippets.

@anilkay
Created May 17, 2024 09:25
Show Gist options
  • Select an option

  • Save anilkay/8d45bc0dc4de3fb19262c16773932576 to your computer and use it in GitHub Desktop.

Select an option

Save anilkay/8d45bc0dc4de3fb19262c16773932576 to your computer and use it in GitHub Desktop.
using NanoidDotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace nanoiddeneme
{
internal class Utils
{
private string CustomAlphabet="abcdefgh12356789";
private int Size = 8;
public Utils(string customAlphabet, int size)
{
CustomAlphabet = customAlphabet;
Size = size;
}
public Utils()
{
}
/// <summary>
/// generated Random Url.
/// </summary>
/// <param name="baseUrl"></param>
/// <param name="path"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal (string generatedUrl, string generatedId) GenerateUrlForUniqueOperation(string baseUrl, string path)
{
if (string.IsNullOrEmpty(baseUrl))
{
throw new ArgumentNullException("baseUrl Cannot be null or empty");
}
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path Cannot be null or empty");
}
string generatedId = Nanoid.Generate(alphabet: CustomAlphabet, size: Size);
string generatedUrl = baseUrl + path + "/" + generatedId;
return (generatedUrl, generatedId);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment