Xamarin.iOS对象丢失属性成员

时间:2019-06-01 22:22:53

标签: c# xamarin xamarin.forms xamarin.ios

我有一个带有UWP,Android和iOS的Xamarin Forms项目。我使用后端托管在Azure中的SQL数据库,用户可以搜索食物并获得食物所附带的不同量度和营养价值。问题是,我使用一个foreach循环来遍历所查询食物的列表,并创建和对象以保留更高级别的食物属性(例如名称和度量),并结合第二个列表,该列表包含该对象的所有营养素和营养素值餐饮。在创建对象的过程中,仅在iOS上,当循环对象中有数据时,未设置Measure属性,在调试模式下,我看到Measure的值为{...},而Measure属性从以下位置消失实例化的对象。这仅在iOS上发生,而不在UWP或Android上发生。这是调试中的图片: Food item with data 这是实例化缺少属性的新对象: NewFood without some properties 这是Measure属性,其中包含我从未见过的内容: Measure Property

这是食物对象类

public class FoodNutrients : BindableObject
    {
        public string NDB { get; set; }
        public string Food { get; set; }
        public string Measure { get; set; }
        public string MeasureType { get; set; }
        public string MeasureAmount { get; set; }
        public double Protein { get; set; }
        public double Sodium { get; set; }
        public double Potassium { get; set; }
        public double Phosphorus { get; set; }
        public double Carbs { get; set; }
        public double Fat { get; set; }
        public double SaturatedFat { get; set; }
        public double Calories { get; set; }
        public string SodiumRec { get; set; }
        public string ProteinRec { get; set; }
        public string PotassiumRec { get; set; }
        public string PhosphorusRec { get; set; }
        public string CarbsRec { get; set; }
        public string FatRec { get; set; }
        public string SatFatRec { get; set; }
        public string CaloriesRec { get; set; }
        public string Recommendation { get; set; }
        public string RecColor { get; set; }
}

这是foreach循环

foreach (var food in foodList1)
                {
                    FoodNutrients newFood = new FoodNutrients();
                    string measureString = "- " + food.MeasureAmount + " " + food.Measure;
                    newFood.NDB = food.NDB;
                    newFood.Food = food.Food;
                    newFood.MeasureType = food.Measure;
                    newFood.MeasureAmount = food.MeasureAmount;
                    newFood.Measure = measureString;
                    newFood.Protein = FoodNutrients.GetProteinValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood.Sodium = FoodNutrients.GetSodiumValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood.Potassium = FoodNutrients.GetPotassiumValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood.Phosphorus = FoodNutrients.GetPhosphorusValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood.Carbs = FoodNutrients.GetCarbValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood.Fat = FoodNutrients.GetFatValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood.SaturatedFat = FoodNutrients.GetSatFatValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood.Calories = FoodNutrients.GetCalorieValue(foodList2, food.NDB, (double)food.MeasureWeightGrams);
                    newFood = DailyAllowanceController.GetRecommendation(newFood, user);
                    foodList.Add(newFood);
                }

同样,没有语法错误,并且此代码字在Android和UWP中完美无缺。请查看上面描述中的图像,因为它们提供了一些真实的细节。

1 个答案:

答案 0 :(得分:0)

我发现您只需要在iOS Build设置Link SDK程序集中设置Linker。然后保存并重建和重新部署,这解决了我的问题。非常令人困惑。