mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 01:41:17 -10:00
51 lines
1.0 KiB
C#
51 lines
1.0 KiB
C#
//
|
|
// System.Xml.Serialization.CodeIdentifier.cs
|
|
//
|
|
// Author:
|
|
// Tim Coleman ([email protected])
|
|
//
|
|
// Copyright (C) Tim Coleman, 2002
|
|
//
|
|
|
|
using System;
|
|
|
|
namespace System.Xml.Serialization {
|
|
public class CodeIdentifier {
|
|
|
|
public CodeIdentifier ()
|
|
{
|
|
}
|
|
|
|
public static string MakeCamel (string identifier)
|
|
{
|
|
string validIdentifier = MakeValid (identifier);
|
|
return (Char.ToLower (validIdentifier[0]) + validIdentifier.Substring (1));
|
|
}
|
|
|
|
public static string MakePascal (string identifier)
|
|
{
|
|
string validIdentifier = MakeValid (identifier);
|
|
return (Char.ToUpper (validIdentifier[0]) + validIdentifier.Substring (1));
|
|
}
|
|
|
|
public static string MakeValid (string identifier)
|
|
{
|
|
if (identifier == null)
|
|
throw new NullReferenceException ();
|
|
if (identifier.Length == 0)
|
|
return identifier;
|
|
|
|
string output = "";
|
|
|
|
if (Char.IsNumber (identifier[0]))
|
|
output = "Item";
|
|
|
|
foreach (char c in identifier)
|
|
if (Char.IsLetterOrDigit (c) || c == '_')
|
|
output += c;
|
|
|
|
return output;
|
|
}
|
|
}
|
|
}
|