private static bool TryParse(PropertyInfo prop, string argStr, out dynamic parsed) { try { if (prop.PropertyType == typeof(int)) { parsed = Convert.ToInt32(argStr); } else if (prop.PropertyType == typeof(long)) { parsed = Convert.ToInt64(argStr); } else if (prop.PropertyType == typeof(short)) { parsed = Convert.ToInt16(argStr); } else if (prop.PropertyType == typeof(float)) { parsed = Convert.ToSingle(argStr); } else if (prop.PropertyType == typeof(double)) { parsed = Convert.ToDouble(argStr); } else if (prop.PropertyType == typeof(string)) { parsed = CqCode.Decode(argStr); // Convert.ToString(cmd); } else if (prop.PropertyType == typeof(bool)) { string tmpCmd = argStr == "" ? "true" : argStr; if (tmpCmd == "0") { tmpCmd = "false"; } else if (tmpCmd == "1") { tmpCmd = "true"; } parsed = Convert.ToBoolean(tmpCmd); } else { throw new NotSupportedException("sb"); } return(true); } catch (Exception ex) { Exception(ex); parsed = null; return(false); } }
private static dynamic ParseStr(PropertyInfo prop, string argStr) { dynamic obj; if (prop.PropertyType == typeof(int)) { obj = Convert.ToInt32(argStr); } else if (prop.PropertyType == typeof(long)) { obj = Convert.ToInt64(argStr); } else if (prop.PropertyType == typeof(short)) { obj = Convert.ToInt16(argStr); } else if (prop.PropertyType == typeof(float)) { obj = Convert.ToSingle(argStr); } else if (prop.PropertyType == typeof(double)) { obj = Convert.ToDouble(argStr); } else if (prop.PropertyType == typeof(string)) { obj = CqCode.Decode(argStr); // Convert.ToString(cmd); } else if (prop.PropertyType == typeof(bool)) { string tmpCmd = argStr == "" ? "true" : argStr; if (tmpCmd == "0") { tmpCmd = "false"; } else if (tmpCmd == "1") { tmpCmd = "true"; } obj = Convert.ToBoolean(tmpCmd); } else { throw new NotSupportedException("sb"); } return(obj); }