From c49c335d2b1d750147ff6c062a5c9eb7e5664a3b Mon Sep 17 00:00:00 2001 From: shinriyo Date: Sat, 24 May 2014 22:36:53 +0900 Subject: [PATCH] Debug.LogError and DRY I found same code. I used just called other's method. And, Error message is Debug.LogError is better. --- Assets/Output/JSONHelper.cs | 114 +++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/Assets/Output/JSONHelper.cs b/Assets/Output/JSONHelper.cs index 9ecdcba..df37b9e 100644 --- a/Assets/Output/JSONHelper.cs +++ b/Assets/Output/JSONHelper.cs @@ -4,57 +4,65 @@ using System; using System.Text; +namespace UnityORM.Helper +{ + public static class JSONHelper + { + public static object Array (params object[] values) + { + return values; + } -namespace UnityORM.Helper{ - - public static class JSONHelper{ - - public static object Array(params object[] values){ - return values; - } - - public static Dictionary Dict(params object[] values){ - Dictionary d = new Dictionary(); - for(int i = 1;i < values.Length;i += 2){ - d.Add(values[i-1].ToString(),values[i]); - } - return d; - } - - public static string Jasonize( params object[] dictValues){ - - Dictionary d = new Dictionary(); - for(int i = 1;i < dictValues.Length;i += 2){ - d.Add(dictValues[i-1].ToString(),dictValues[i]); - } - return UnityORM.Json.Serialize(d); - } - - - public static T GetGet(this IDictionary dict,string key1,string key2){ - IDictionary d; - try{ - d = (IDictionary)dict[key1]; - if(d == null){ - Debug.Log("Key:" + key1 + " not found"); - return default(T); - } - }catch(InvalidCastException e){ - Debug.Log("Wrong cast at key:" + key1 + ";" + e.Message); - return default(T); - } - return (T)d[key2]; - } - public static T Get(this IDictionary dict,string key){ - return (T)dict[key]; - } - - public static IList GetList(this IDictionary dict, string key){ - return (IList)dict[key]; - } - public static IDictionary GetDict(this IDictionary dict,string key){ - return (IDictionary)dict[key]; - } - - } -} \ No newline at end of file + public static Dictionary Dict (params object[] values) + { + Dictionary d = new Dictionary (); + for (int i = 1; i < values.Length; i += 2) + { + d.Add (values [i - 1].ToString (), values [i]); + } + return d; + } + + public static string Jasonize (params object[] dictValues) + { + Dictionary d = Dict(dictValues); + + return UnityORM.Json.Serialize (d); + } + + public static T GetGet (this IDictionary dict, string key1, string key2) + { + IDictionary d; + try + { + d = (IDictionary)dict [key1]; + if (d == null) + { + Debug.Log ("Key:" + key1 + " not found"); + return default(T); + } + } + catch (InvalidCastException e) + { + Debug.LogError ("Wrong cast at key:" + key1 + ";" + e.Message); + return default(T); + } + return (T)d [key2]; + } + + public static T Get (this IDictionary dict, string key) + { + return (T)dict [key]; + } + + public static IList GetList (this IDictionary dict, string key) + { + return (IList)dict [key]; + } + + public static IDictionary GetDict (this IDictionary dict, string key) + { + return (IDictionary)dict [key]; + } + } +}