IList<string> _Temp= Zgke.Test.SqlText.GetValueTryParse("True");
//返回一个 System.Boolean
_Temp = Zgke.Test.SqlText.GetValueTryParse("2009-10-11");
//返回 System.DateTime 和 System.DateTimeOffset;
_Temp = Zgke.Test.SqlText.GetValueTryParse("111.111");
// 返回 System.Decimal System.Double System.Single
_Temp = Zgke.Test.SqlText.GetValueTryParse("11111111111111");
//返回 System.Decimal System.Double System.Single System.Int64 System.UInt64
下面是全部方法
/// <summary> /// 根据传递的字符串判断可以用什么类型进行 TryParse [email protected] qq:116149 /// </summary> /// <param name="p_Value">类型</param> /// <returns>可以用TryParse的类名</returns> public static IList<string> GetValueTryParse(string p_Value) { IList<string> _TryType = new List<string>(); Assembly _Assembly = Assembly.Load("mscorlib"); Type[] _TypeList = _Assembly.GetTypes(); foreach (Type _TypeInfo in _TypeList) { if (_TypeInfo.IsSerializable == false) continue; MethodInfo _Method = _TypeInfo.GetMethod("TryParse", new Type[] { Type.GetType("System.String"), Type.GetType(_TypeInfo.FullName + "&") }); if (_Method == null) continue; object _ObjectValue = Activator.CreateInstance(_TypeInfo); bool _Value = (bool)_Method.Invoke(null, new object[] { p_Value, _ObjectValue }); if (_Value == true) _TryType.Add(_TypeInfo.FullName); } return _TryType; }