示例#1
0
        public KeyValuePair <string, string> GetCardDefinitionByName()
        {
            StreamReader deckOfManyThings = new StreamReader("deckOfManyThings.json");
            string       json             = deckOfManyThings.ReadToEnd();
            List <Card>  Cards            = JsonConvert.DeserializeObject <List <Card> >(json);

            var cardDefinition = KeyValuePair
                                 .Create(
                Cards.Where(c => c.CardName.ToLower() == CardName.ToLower()).Select(c => c.CardName).FirstOrDefault() ?? "No card found",
                Cards.Where(c => c.CardName.ToLower() == CardName.ToLower()).Select(c => c.Definition).FirstOrDefault() ?? "No card description found"
                );

            return(cardDefinition);
        }