1 using Microsoft.CSharp;
13 internal const int MaxIdentifierLength = 511;
16 [Obsolete(
"This class should never get constructed as it contains only static methods.")]
27 if (identifier.Length <= 2)
31 if (
char.IsLower(identifier[0]))
44 if (identifier.Length <= 2)
48 if (
char.IsUpper(identifier[0]))
61 for (
int i = 0; i < identifier.Length; i++)
63 if (stringBuilder.
Length >= 511)
67 char c = identifier[i];
70 if (stringBuilder.
Length == 0 && !IsValidStart(c))
72 stringBuilder.
Append(
"Item");
77 if (stringBuilder.
Length == 0)
84 internal static string MakeValidInternal(
string identifier)
86 if (identifier.Length > 30)
93 private static bool IsValidStart(
char c)
102 private static bool IsValid(
char c)
104 switch (
char.GetUnicodeCategory(c))
143 internal static void CheckValidIdentifier(
string ident)
147 throw new ArgumentException(Res.GetString(
"XmlInvalidIdentifier", ident),
"ident");
151 internal static string GetCSharpName(
string name)
153 return EscapeKeywords(name.Replace(
'+',
'.'), csharp);
156 private static int GetCSharpName(Type t, Type[] parameters,
int index,
StringBuilder sb)
158 if (t.DeclaringType !=
null && t.DeclaringType != t)
160 index = GetCSharpName(t.DeclaringType, parameters, index, sb);
163 string name = t.Name;
164 int num = name.IndexOf(
'`');
167 num = name.IndexOf(
'!');
171 EscapeKeywords(name.Substring(0, num), csharp, sb);
176 sb.
Append(GetCSharpName(parameters[index]));
177 if (index < num2 - 1)
187 EscapeKeywords(name, csharp, sb);
192 internal static string GetCSharpName(Type t)
197 t = t.GetElementType();
201 stringBuilder.
Append(
"global::");
202 string @
namespace = t.Namespace;
203 if (@
namespace !=
null && @
namespace.Length > 0)
205 string[] array = @
namespace.Split(
'.');
206 for (
int i = 0; i < array.Length; i++)
208 EscapeKeywords(array[i], csharp, stringBuilder);
209 stringBuilder.
Append(
".");
212 Type[] parameters = (t.IsGenericType || t.ContainsGenericParameters) ? t.GetGenericArguments() :
new Type[0];
213 GetCSharpName(t, parameters, 0, stringBuilder);
214 for (
int j = 0; j < num; j++)
216 stringBuilder.
Append(
"[]");
223 if (identifier !=
null && identifier.Length != 0)
225 string text = identifier;
230 identifier = identifier.Substring(0, identifier.Length - 2);
232 if (identifier.Length > 0)
234 CheckValidIdentifier(identifier);
238 for (
int i = 0; i < num; i++)
245 private static string EscapeKeywords(
string identifier,
CodeDomProvider codeProvider)
247 if (identifier ==
null || identifier.Length == 0)
251 string[] array = identifier.Split(
'.',
',',
'<',
'>');
254 for (
int i = 0; i < array.Length; i++)
258 stringBuilder.
Append(identifier.Substring(num, 1));
261 num += array[i].Length;
262 string identifier2 = array[i].Trim();
263 EscapeKeywords(identifier2, codeProvider, stringBuilder);
265 if (stringBuilder.
Length == identifier.Length)
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
static string MakeCamel(string identifier)
Produces a camel-case string from an input string.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Provides an example implementation of the T:System.CodeDom.Compiler.ICodeGenerator interface....
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
CodeIdentifier()
Initializes a new instance of the T:System.Xml.Serialization.CodeIdentifier class.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static bool IsValidLanguageIndependentIdentifier(string value)
Gets a value indicating whether the specified string is a valid identifier.
virtual string CreateEscapedIdentifier(string value)
Creates an escaped identifier for the specified value.
static string MakeValid(string identifier)
Produces a valid code entity name from an input string.
UnicodeCategory
Defines the Unicode category of a character.
static string MakePascal(string identifier)
Produces a Pascal-case string from an input string.
Provides a base class for T:System.CodeDom.Compiler.CodeDomProvider implementations....
Provides information about a specific culture (called a locale for unmanaged code development)....
Provides static methods to convert input text into names for code entities.