类似这样很复杂的配置表 解析起来需要很长篇的代码, 但是作为一个程序肯定不能让自己的代码这么长篇大论 所以我们需要用很短的代码来解析 读取里面全部数据
var cfgProperty = ConfigMgr.Ins.GetTreasureTableConfigMap () [id];//这是拿到了这个表
List<TreasureTable> lists = new List<TreasureTable> ();//用来存取新的结构 的类
System.Reflection.PropertyInfo [] info = cfgProperty.GetType ().GetProperties ();
for ( int i = 0 ; i < info.Length ; i++ )
{
if ( info [i].Name == "Parser" || info [i].Name == "Descriptor" || info [i].Name == "Id" || info [i].Name == "Note" )
{
continue;//跳过/排除不需要的内容
}
if ( info [i].GetValue (cfgProperty , null) == null || ( int ) info [i + 1].GetValue (cfgProperty , null) == 0 )
{
break;//遇到空的内容说明结束了
}
//对应把值取出来
string table = ( string ) info [i].GetValue (cfgProperty , null);
int dropItem = ( int ) info [i + 1].GetValue (cfgProperty , null);
int upLimit = ( int ) info [i + 2].GetValue (cfgProperty , null);
int lowLimit = ( int ) info [i + 3].GetValue (cfgProperty , null);
TreasureTable sr = new TreasureTable (table , dropItem , upLimit , lowLimit);//取出来的值实例化出新的类
lists.Add (sr);//把类存进列表里
i += 3;//上面取值i+3了 , 我们下一次取值也直接i+3开始(可i+n)
}
这样子整个列表就被取出来存进新的类了 不用再很麻烦的一个个取值了