public static void Test() { PrimitiveTypes32 val; var sArray = new string[] { "true", "false", "@", "123", "123.4f", "123.4", "1", "1.", "1f", "@ExpressionTypeIndex", "@DifficultyIndex", }; foreach (var s in sArray) { if (PrimitiveTypes32.TryParse(s, out val)) { Debug.Log("\"" + s + "\"->" + "val:" + val.ToString()); } else { Debug.Log("PrimitiveTypes32.TryParse(\"" + s + "\") returns false."); } } }
public static bool TryParse(string s, out PrimitiveTypes32 result) { result = new PrimitiveTypes32(); { if (bool.TryParse(s, out result.value._bool)) { result.typeCode = TypeCode.Boolean; return(true); } } { if (int.TryParse(s, out result.value._int)) { result.typeCode = TypeCode.Int32; return(true); } } { if (s.EndsWith("f", true, null)) { // sが"f"か"F"で終わる. var s1 = s.Substring(0, s.Length - 1); if (float.TryParse(s1, out result.value._float)) { result.typeCode = TypeCode.Single; return(true); } } else { if (float.TryParse(s, out result.value._float)) { result.typeCode = TypeCode.Single; return(true); } } } { if (char.TryParse(s, out result.value._char)) { result.typeCode = TypeCode.Char; return(true); } } { if (s.StartsWith("@")) { // sが"@"で始まる. var key = s.Substring(1); var s1 = Jam.InGameDataManager.instance.GetString(key); if (TryParse(s1, out result)) { return(true); } } } return(false); }
public static PrimitiveTypes32 ParsePrimitiveTypes32(this string self, PrimitiveTypes32 defaultValue) { PrimitiveTypes32 val; if (PrimitiveTypes32.TryParse(self, out val)) { #if LOG_DETAIL Debug.LogWarning("at \"" + self + "\"" + "." + MethodBase.GetCurrentMethod().Name + "(defaultValue:" + defaultValue + ")\n PrimitiveTypes32.TryParse(\"" + self + "\") returns false."); #endif val = defaultValue; } return(val); }