internal static string GenerateIdName(string name, CodeDomProvider codeProvider, bool useSuffix, int additionalCharsToTruncate)
{
if (!useSuffix)
{
name = GetBackwardCompatibleIdentifier(name, codeProvider);
}
if (codeProvider.IsValidIdentifier(name))
{
return name;
}
string str = name.Replace(' ', '_');
if (!codeProvider.IsValidIdentifier(str))
{
if (!useSuffix)
{
str = "_" + str;
}
for (int i = 0; i < str.Length; i++)
{
UnicodeCategory unicodeCategory = char.GetUnicodeCategory(str[i]);
if (((((unicodeCategory != UnicodeCategory.UppercaseLetter) && (UnicodeCategory.LowercaseLetter != unicodeCategory)) && ((UnicodeCategory.TitlecaseLetter != unicodeCategory) && (UnicodeCategory.ModifierLetter != unicodeCategory))) && (((UnicodeCategory.OtherLetter != unicodeCategory) && (UnicodeCategory.NonSpacingMark != unicodeCategory)) && ((UnicodeCategory.SpacingCombiningMark != unicodeCategory) && (UnicodeCategory.DecimalDigitNumber != unicodeCategory)))) && (UnicodeCategory.ConnectorPunctuation != unicodeCategory))
{
str = str.Replace(str[i], '_');
}
}
}
int num2 = 0;
string str2 = str;
while (!codeProvider.IsValidIdentifier(str) && (num2 < 200))
{
num2++;
str = "_" + str;
}
if (num2 >= 200)
{
str = str2;
while (!codeProvider.IsValidIdentifier(str) && (str.Length > 0))
{
str = str.Remove(str.Length - 1);
}
if (str.Length == 0)
{
return str2;
}
if (((additionalCharsToTruncate > 0) && (str.Length > additionalCharsToTruncate)) && codeProvider.IsValidIdentifier(str.Remove(str.Length - additionalCharsToTruncate)))
{
str = str.Remove(str.Length - additionalCharsToTruncate);
}
}
return str;
}