예제 #1
0
 public LibraryInfo(string name, Dictionary <string, string> natives, List <RuleInfo> rules, LibraryDownloadsInfo downloads)
 {
     Name      = name;
     Natives   = natives;
     Rules     = rules;
     Downloads = downloads;
 }
예제 #2
0
        public static LibraryInfo Parse(JObject json)
        {
            JToken temp;

            string name = null;
            Dictionary <string, string> natives   = new Dictionary <string, string>();
            List <RuleInfo>             rules     = new List <RuleInfo>();
            LibraryDownloadsInfo        downloads = new LibraryDownloadsInfo();

            if (json.TryGetValue("name", out temp) && temp.Type == JTokenType.String)
            {
                name = temp.ToString();
            }
            if (json.TryGetValue("natives", out temp) && temp.Type == JTokenType.Object)
            {
                foreach (KeyValuePair <string, JToken> jsonPro in JObject.Parse(temp.ToString()))
                {
                    if (jsonPro.Value.Type == JTokenType.String)
                    {
                        natives.Add(jsonPro.Key, jsonPro.Value.ToString());
                    }
                }
            }
            if (json.TryGetValue("rules", out temp) && temp.Type == JTokenType.Array)
            {
                foreach (JToken jsonTok in JArray.Parse(temp.ToString()))
                {
                    if (jsonTok.Type == JTokenType.Object)
                    {
                        rules.Add(RuleInfo.Parse(JObject.Parse(jsonTok.ToString())));
                    }
                }
            }
            if (json.TryGetValue("downloads", out temp) && temp.Type == JTokenType.Object)
            {
                downloads = LibraryDownloadsInfo.Parse(JObject.Parse(temp.ToString()));
            }

            return(new LibraryInfo(name, natives, rules, downloads));
        }