how to use?

dynamic obj=new SmartObject(); //define a smartobject
obj.Name="jim"; //define a property
obj["Age"]=28; //you can define a property like this too.
obj.IsDefine("C"); //Judge the obj's property isn't defined? return false;
obj.IsDefine("Age"); //return true;
string name=obj["Name"]; //you can visit a property with the property's name.
name=obj.Name;
name=obj[0]; //you can visit a property with the property's index.
obj.Info=new SmartObject(); //define a SmartObject type property
obj.Info.Job="PL";
obj.Info.Salary=20000;
obj.Goods=new List<SmartObject>(); //defined a collection property.
obj.Goods.Add(new SmartObject());
obj.Goods.Add(new SmartObject());
obj.Goods.Add(new SmartObject());
obj.Goods[0].NO="1001";
obj.Goods[0].Name="Apple";
obj.Goods[0].Price=2.2;
obj.Goods[1].NO="1004";
obj.Goods[1].Name="Tea";
obj.Goods[1].Price=23.9;
obj.Goods[2].NO="1008";
obj.Goods[2].Name="Phone";
obj.Goods[2].Price=52.8;
string json=obj.ToJson(); //convert a SmartObject to a json string.
dynamic o2=SmartObject.Parse(json); //convert a json string to a SmartObject.
IList<KeyValuePair<string,object>> lst=obj.AsList(); //convert a SmartObject to a IList.
IDictionary<string,object> dict=obj.AsDictionary();//convert a SmartObject to a Dictionary.

Last edited Dec 26, 2013 at 12:43 AM by kingge168, version 3