Created
August 26, 2017 17:50
-
-
Save JeremyLikness/46e8f933637ee009328e30ea63a641c7 to your computer and use it in GitHub Desktop.
Deserializing the nutrient list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void DeserializeNutrients(string tag = null) | |
| { | |
| var elements = this.NutrientDoc["nutrients"].AsBsonDocument; | |
| var list = new List<Nutrient>(); | |
| foreach (var element in elements.Elements) | |
| { | |
| if (!string.IsNullOrWhiteSpace(tag)) { | |
| if (element.Name != tag) { | |
| continue; | |
| } | |
| } | |
| var nutrient = new Nutrient | |
| { | |
| FoodId = this.FoodId, | |
| NutrientId = element.Value.AsBsonDocument["id"].AsString, | |
| AmountInHundredGrams = element.Value.AsBsonDocument["amount"].ToDouble(), | |
| Definition = new NutrientDefinition | |
| { | |
| NutrientId = element.Value.AsBsonDocument["id"].AsString, | |
| UnitOfMeasure = element.Value.AsBsonDocument["uom"].AsString, | |
| Description = element.Value.AsBsonDocument["description"].AsString, | |
| TagName = element.Name, | |
| SortOrder = element.Value.AsBsonDocument["sortOrder"].AsInt32 | |
| } | |
| }; | |
| list.Add(nutrient); | |
| } | |
| this.Nutrients = list.ToArray(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment