pascalabcnet/CoreUtils/GeneratedNamesManager.cs
Александр Земляк aa2b09dd3b
Настройка проекта PABCCoreUtils (#3406)
* Rename Utils project to PABCCoreUtils

* Move FormatTools from ParserTools project to PABCCoreUtils

* Move SourceFilesProviders class and FileReader class to PABCCoreUtils
2026-03-13 08:02:04 +03:00

27 lines
1.1 KiB
C#

// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
// Данный проект не зависит от других проектов
using System.Collections.Generic;
namespace PascalABCCompiler.CoreUtils
{
/// <summary>
/// Хранилище для сгенерированных компилятором переменных
/// </summary>
public class GeneratedNamesManager
{
private readonly Dictionary<string, int> counters = new Dictionary<string, int>();
/// <summary>
/// Возвращает уникальное имя для переданного префикса (используется автоинкремент)
/// </summary>
public string GenerateName(string prefix, string suffix = "")
{
counters.TryGetValue(prefix, out int current);
counters[prefix] = current + 1;
return $"{prefix}{current}{suffix}";
}
}
}