c#创建对象并动态添加属性

 1 //动态类,可以作为基类被继承
 2 dynamic backObj = new ExpandoObject();  //ExpandoObject 为密封类
 3                 backObj.image0 = IMGNAMELIST0;
 4                 backObj.image1 = IMGNAMELIST1;
 5                 backObj.asset = ASSET;
 6                 backObj.indexData = (dsIndex!=null)?dsIndex.Tables[0]:null;
 7 
 8                 return new StringRespond()
 9                 {
10                     RespondSuc = true,
11                     RespondString = JsonConvert.SerializeObject(backObj)
12                 };

 

posted @ 2016-11-27 14:56  风谷逍遥客  阅读(9831)  评论(1编辑  收藏  举报