public virtual void WriteType(Type ty)
{
if (ty.IsGenericType && (ty.GetGenericTypeDefinition() == typeof(Nullable<>)))
{
WriteType(ty.GetGenericArguments()[0]);
WriteOperator("?");
}
else if (ty.IsGenericType)
{
// FIXME: generate a comma-delimited list of arguments
Output(ty.Name.Remove(ty.Name.Length - 2), ty.IsValueType ? TokenType.ValueType : ty.IsInterface ? TokenType.InterfaceType : TokenType.ClassType, ty);
WriteOperator("<");
Type[] args = ty.GetGenericArguments();
for (int i = 0; i < args.Length; ++i)
{
WriteType(args[i]);
if (i < args.Length - 1)
{
WriteOperator(",");
WriteWhitespace(" ");
}
}
WriteOperator(">");
}
else if (ty == typeof(void))
{
WriteKeyword("void");
}
else if (ty == typeof(string))
{
WriteKeyword("string");
}
else if (ty.IsPrimitive)
{
if (ty == typeof(int)) WriteKeyword("int");
else if (ty == typeof(bool)) WriteKeyword("bool");
else if (ty == typeof(decimal)) WriteKeyword("decimal");
else if (ty == typeof(char)) WriteKeyword("char");
else if (ty == typeof(sbyte)) WriteKeyword("sbyte");
else if (ty == typeof(byte)) WriteKeyword("byte");
else if (ty == typeof(short)) WriteKeyword("short");
else if (ty == typeof(ushort)) WriteKeyword("ushort");
else if (ty == typeof(uint)) WriteKeyword("uint");
else if (ty == typeof(long)) WriteKeyword("long");
else if (ty == typeof(ulong)) WriteKeyword("ulong");
else if (ty == typeof(double)) WriteKeyword("double");
else if (ty == typeof(float)) WriteKeyword("float");
else WriteComment(String.Format("/* UNKNOWN PRIMITIVE TYPE {0} */", ty.FullName));
}
// TODO: other CLR to C# conversions here...
else
{
Output(ty.Name, ty.IsValueType ? TokenType.ValueType : ty.IsInterface ? TokenType.InterfaceType : TokenType.ClassType, ty);
}
}