Пример #1
0
        public List <AbstractDataset> GetDatasets(string datasetStore)
        {
            var dbDatasets = StoreProvider.GetCompleteStore(datasetStore);

            var datasets    = new List <AbstractDataset>();
            var datasetType = Type.GetType($"BusinessLogic.Models.{datasetStore}");

            foreach (var dbDataset in dbDatasets)
            {
                var dataset = Activator.CreateInstance(datasetType);
                foreach (var key in dbDataset.Keys)
                {
                    var property = datasetType.GetProperty(key);
                    if (property == null)
                    {
                        continue;
                    }

                    var value = dbDataset[key] == DBNull.Value ? null : dbDataset[key];
                    if (property.PropertyType == typeof(bool))
                    {
                        switch (value)
                        {
                        case "0":
                            value = false;
                            break;

                        case "1":
                            value = true;
                            break;
                        }
                    }

                    value = Convert.ChangeType(value, property.PropertyType);

                    property.SetValue(dataset, value);
                }
                datasets.Add(dataset as AbstractDataset);
            }

            return(datasets);
        }