コード例 #1
0
        public List <dynamic> DeSerialableBaseDatas(List <String> keys)
        {
            List <dynamic> BaseDatas    = new List <dynamic>();
            List <int>     columnIndexs = new List <int>();

            foreach (var key in keys)
            {
                int colunnIndex = -1;
                for (int i = 0; i < this.workSheet.GetRow(0).LastCellNum; i++)
                {
                    if (this.workSheet.GetRow(0).GetCell(i).StringCellValue == key)
                    {
                        colunnIndex = i;
                        break;
                    }
                }
                columnIndexs.Add(colunnIndex);
            }
            for (int i = 0; i < this.workSheet.LastRowNum; i++)
            {
                dynamic BaseData = new DynamicModel();
                for (int j = 0; j < keys.Count; j++)
                {
                    BaseData.PropertyName = keys[j];
                    BaseData.Property     = this.workSheet.GetRow(i).GetCell(columnIndexs[j]).StringCellValue;
                }
                BaseDatas.Add(BaseData);
            }
            return(BaseDatas);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("动态为类型添加属性");
            dynamic       dynamicModel = new DynamicModel();
            List <string> myList       = new List <string>();

            myList.Add("Name");
            myList.Add("Age");
            myList.Add("Hobby");

            List <string> myValueList = new List <string>();

            myValueList.Add("Mary");
            myValueList.Add("18");
            myValueList.Add("Dance");
            dynamicModel.         = "fadsfadsfasd";
            dynamicModel.Property = "fdsafdsafsad";


            //for (int i = 0; i < myList.Count; i++)
            //{
            //    string myAttr = myList[i];
            //    dynamicModel.PropertyName = myAttr;
            //    dynamicModel.Property = myValueList[i];
            //}

            Console.WriteLine($"Name: {dynamicModel.Name}");
            Console.WriteLine($"Age: {dynamicModel.Age}");
            Console.WriteLine($"Hobby: {dynamicModel.Hobby}");
        }
コード例 #3
0
        static public List <dynamic> extractBaseData <T>(List <T> dataList)
        {
            var BaseDatas = dataList.Select(r =>
            {
                Type R    = typeof(T);
                dynamic d = new DynamicModel();
                foreach (var field in R.GetFields())
                {
                    if (field.FieldType.Name == "BaseData")
                    {
                        d.PropertyName = field.Name;
                        dynamic value  = field.GetValue(r);
                        d.Property     = value.data;
                    }
                }
                return(d);
            }).ToList();

            return(BaseDatas);
        }