C#根据字符串获取对应类型(Type) 转


C#根据字符串获取对应类型(Type)

public static Type GetTypeByString(string type)
        {
            switch (type.ToLower())
            {
                case "bool":
                    return Type.GetType("System.Boolean"truetrue);
                case "byte":
                    return Type.GetType("System.Byte"truetrue);
                case "sbyte":
                    return Type.GetType("System.SByte"truetrue);
                case "char":
                    return Type.GetType("System.Char"truetrue);
                case "decimal":
                    return Type.GetType("System.Decimal"truetrue);
                case "double":
                    return Type.GetType("System.Double"truetrue);
                case "float":
                    return Type.GetType("System.Single"truetrue);
                case "int":
                    return Type.GetType("System.Int32"truetrue);
                case "uint":
                    return Type.GetType("System.UInt32"truetrue);
                case "long":
                    return Type.GetType("System.Int64"truetrue);
                case "ulong":
                    return Type.GetType("System.UInt64"truetrue);
                case "object":
                    return Type.GetType("System.Object"truetrue);
                case "short":
                    return Type.GetType("System.Int16"truetrue);
                case "ushort":
                    return Type.GetType("System.UInt16"truetrue);
                case "string":
                    return Type.GetType("System.String"truetrue);
                case "date":
                case "datetime":
                    return Type.GetType("System.DateTime"truetrue);
                case "guid":
                    return Type.GetType("System.Guid"truetrue);
                default:
                    return Type.GetType(type, truetrue);
            }
        }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM