| | |
| | | using System; |
| | | using System.Reflection; |
| | | using System.Linq; |
| | | |
| | | namespace XLua |
| | | { |
| | | |
| | | public static class TypeExtensions |
| | | internal static class TypeExtensions |
| | | { |
| | | public static bool IsValueType(this Type type) |
| | | { |
| | |
| | | return type.GetTypeInfo().IsPublic; |
| | | #endif |
| | | } |
| | | |
| | | public static string GetFriendlyName(this Type type) |
| | | { |
| | | if (type == typeof(int)) |
| | | return "int"; |
| | | else if (type == typeof(short)) |
| | | return "short"; |
| | | else if (type == typeof(byte)) |
| | | return "byte"; |
| | | else if (type == typeof(bool)) |
| | | return "bool"; |
| | | else if (type == typeof(long)) |
| | | return "long"; |
| | | else if (type == typeof(float)) |
| | | return "float"; |
| | | else if (type == typeof(double)) |
| | | return "double"; |
| | | else if (type == typeof(decimal)) |
| | | return "decimal"; |
| | | else if (type == typeof(string)) |
| | | return "string"; |
| | | else if (type.IsGenericType) |
| | | return type.FullName.Split('`')[0] + "<" + string.Join(", ", type.GetGenericArguments().Select(x => GetFriendlyName(x)).ToArray()) + ">"; |
| | | else |
| | | return type.FullName; |
| | | } |
| | | } |
| | | } |