Files
mono/mcs/class/System.XML/System.Xml.Serialization/CodeIdentifier.cs
T
Paolo Molaro 709ab3e684 Fix build.
svn path=/trunk/mcs/; revision=6166
2002-07-25 11:06:50 +00:00

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;
}
}
}