diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index fdc7294..e81c2c1 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -43,11 +43,8 @@ namespace shadowsocks_csharp.Model { try { - var json = "[0,1,2]"; - var result = SimpleJson.SimpleJson.DeserializeObject>(json); - string configContent = File.ReadAllText(CONFIG_FILE); - Configuration config = SimpleJson.SimpleJson.DeserializeObject(configContent); + Configuration config = SimpleJson.SimpleJson.DeserializeObject(configContent, new JsonSerializerStrategy()); config.isDefault = false; return config; } @@ -129,5 +126,18 @@ namespace shadowsocks_csharp.Model throw new ArgumentException("server can not be blank"); } } + + private class JsonSerializerStrategy : SimpleJson.PocoJsonSerializerStrategy + { + // convert string to int + public override object DeserializeObject(object value, Type type) + { + if (type == typeof(Int32) && value.GetType() == typeof(string)) + { + return Int32.Parse(value.ToString()); + } + return base.DeserializeObject(value, type); + } + } } } diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 854836e..ca356a6 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -60,7 +60,7 @@ true bin\x86\Debug\ - TRACE;DEBUG + TRACE;DEBUG;SIMPLE_JSON_REFLECTIONEMIT full x86 prompt diff --git a/shadowsocks-csharp/simple-json b/shadowsocks-csharp/simple-json index 663c62a..6b632fd 160000 --- a/shadowsocks-csharp/simple-json +++ b/shadowsocks-csharp/simple-json @@ -1 +1 @@ -Subproject commit 663c62a77ab3318f04ddb9449b2b882364709625 +Subproject commit 6b632fd304736788227e709b87e5bcf59bb4911d