ソースコード
using System;
public static class TypeExt
{
public static string GetAliasName( this Type self )
{
switch ( self.FullName )
{
case "System.Boolean": return "bool";
case "System.Byte": return "byte";
case "System.SByte": return "sbyte";
case "System.Char": return "char";
case "System.Decimal": return "decimal";
case "System.Double": return "double";
case "System.Single": return "float";
case "System.Int32": return "int";
case "System.UInt32": return "uint";
case "System.Int64": return "long";
case "System.UInt64": return "ulong";
case "System.Object": return "object";
case "System.Int16": return "short";
case "System.UInt16": return "ushort";
case "System.String": return "string";
case "System.Void": return "void";
}
return self.Name;
}
}
使用例
var builder = new StringBuilder();
builder.AppendLine( typeof( bool ).GetAliasName() );
builder.AppendLine( typeof( byte ).GetAliasName() );
builder.AppendLine( typeof( char ).GetAliasName() );
builder.AppendLine( typeof( decimal ).GetAliasName() );
builder.AppendLine( typeof( short ).GetAliasName() );
builder.AppendLine( typeof( int ).GetAliasName() );
builder.AppendLine( typeof( long ).GetAliasName() );
builder.AppendLine( typeof( object ).GetAliasName() );
builder.AppendLine( typeof( sbyte ).GetAliasName() );
builder.AppendLine( typeof( float ).GetAliasName() );
builder.AppendLine( typeof( string ).GetAliasName() );
builder.AppendLine( typeof( uint ).GetAliasName() );
builder.AppendLine( typeof( ulong ).GetAliasName() );
Debug.Log( builder );