Repository: dotnet/maui
File: src/Controls/src/SourceGen/NamingHelpers.cs (C#)

Code before:

		SymbolDisplayFormat ShortFormat =
		new(
			globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.OmittedAsContaining,
			typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameOnly,
			propertyStyle: SymbolDisplayPropertyStyle.NameOnly,
			parameterOptions: SymbolDisplayParameterOptions.IncludeName,
			miscellaneousOptions:
				SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
				SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

#pragma warning disable RS0030 // Do not use banned APIs
		return CreateUniqueVariableNameImpl(context, symbol.ToDisplayString(ShortFormat) + suffix, lowFirst);
#pragma warning restore RS0030 // Do not use banned APIs
	}

	static string CreateUniqueVariableNameImpl(SourceGenContext context, string baseName, bool lowFirst)
	{
		baseName = CamelCase(baseName, lowFirst);
		var lastIdForContext = context.lastIdForName;
		var lastId = 0;
		lock (lastIdForContext)
		{
			if (!lastIdForContext.TryGetValue(baseName, out lastId))
				lastId = 0;

			lastIdForContext[baseName] = lastId + 1;
		}
		return lastId == 0 && SyntaxFacts.GetKeywordKind(baseName) == SyntaxKind.None ? baseName : $"{baseName}{lastId}";
	}

	static string CamelCase(string name, bool lowFirst)
	{
		name = name.Replace(".", "_");
		if (string.IsNullOrEmpty(name))
			return name;
		name = Regex.Replace(name, "([A-Z])([A-Z]+)($|[A-Z])", m => m.Groups[1].Value + m.Groups[2].Value.ToLowerInvariant() + m.Groups[3].Value);
		
		return lowFirst ? char.ToLowerInvariant(name[0]) + name.Substring(1) : name;
	}
}

Review comment (suggestion):
```suggestion
			if (!lastIdForContext.TryGetValue(baseName, out lastId))
			{
				lastId = 0;
			}
```

Code after:

		SymbolDisplayFormat ShortFormat =
		new(
			globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.OmittedAsContaining,
			typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameOnly,
			propertyStyle: SymbolDisplayPropertyStyle.NameOnly,
			parameterOptions: SymbolDisplayParameterOptions.IncludeName,
			miscellaneousOptions:
				SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
				SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

#pragma warning disable RS0030 // Do not use banned APIs
		return CreateUniqueVariableNameImpl(context, symbol.ToDisplayString(ShortFormat) + suffix, lowFirst);
#pragma warning restore RS0030 // Do not use banned APIs
	}

	static string CreateUniqueVariableNameImpl(SourceGenContext context, string baseName, bool lowFirst)
	{
		baseName = CamelCase(baseName, lowFirst);
		var lastIdForContext = context.lastIdForName;
		var lastId = 0;
		lock (lastIdForContext)
		{
			if (!lastIdForContext.TryGetValue(baseName, out lastId))
			{
				lastId = 0;
			}

			lastIdForContext[baseName] = lastId + 1;
		}
		return lastId == 0 && SyntaxFacts.GetKeywordKind(baseName) == SyntaxKind.None ? baseName : $"{baseName}{lastId}";
	}

	static string CamelCase(string name, bool lowFirst)
	{
		name = name.Replace(".", "_");
		if (string.IsNullOrEmpty(name))
			return name;
		name = Regex.Replace(name, "([A-Z])([A-Z]+)($|[A-Z])", m => m.Groups[1].Value + m.Groups[2].Value.ToLowerInvariant() + m.Groups[3].Value);
		
		return lowFirst ? char.ToLowerInvariant(name[0]) + name.Substring(1) : name;
	}
}