一个配置文件的Mapping

1. 需要Mapping的Xml结构

 
  
<? xml version="1.0" encoding="utf-8" ?>
< Requestes >
< Request name ="RequestA" formname ="LanguageUI" serviceurl ="http://MyComputer/LanguageService" httpmethod ="POST" targetui ="Settings->LanuageSetting" >
< Reference name ="ClassA" >
< Property name ="DateFrom" type ="DateTime?" />
< Property name ="DateTo" type ="DateTime?" />
</ Reference >
</ Request >
< Request name ="RequestB" formname ="ImageShowUI" serviceurl ="http://MyComputer/ImageService" httpmethod ="POST" targetui ="Settings->Images" >
< Reference name ="ClassB" >
< Property name ="Top" type ="int" />
</ Reference >
</ Request >
</ Requestes >

2. Mapping到的类结构

 

 
  
public class PropertyInfo
{
public string PropertyName
{
get ;
set ;
}
public string PropertyType
{
get ;
set ;
}
}
public class DynamicEntity
{
public string Name
{
get ;
set ;
}
public string ServiceURL
{
get ;
set ;
}
public string TargetUI
{
get ;
set ;
}
public List < PropertyInfo > SimplePropertyList { get ; set ; }
public Dictionary < string , List < PropertyInfo >> CollectivePropertyList { get ; set ; }
public List < RefenceInfo > RefenceList
{
get ;
set ;
}
public string HttpMehtod
{
get ;
set ;
}
public string FormName
{
get ;
set ;
}
}
public class RefenceInfo
{
public string Key
{
get ;
set ;
}
public List < PropertyInfo > SimplePropertyList { get ; set ; }
public Dictionary < string , List < PropertyInfo >> CollectivePropertyList { get ; set ; }
public List < RefenceInfo > RefenceList { get ; set ; }
}

 3. Mapping的方法

 
  
public static List < DynamicEntity > Generate( string xmlPath, string formName)
{
XElement main
= XElement.Load(xmlPath);

return
(from c
in main.Elements( " Request " )
where c.Attribute( " formname " ).Value == formName
select
new DynamicEntity
{
Name
= c.Attribute( " name " ).Value,
ServiceURL
= c.Attribute( " serviceurl " ).Value,
TargetUI
= c.Attribute( " targetui " ).Value,
HttpMehtod
= c.Attribute( " httpmethod " ).Value,
FormName
= c.Attribute( " formname " ).Value,
SimplePropertyList
= c.Elements( " Property " ).Where(p => p.Attribute( " type " ).Value.Trim().ToLower() != " list " ).Select(p => new PropertyInfo { PropertyName = p.Attribute( " name " ).Value, PropertyType = p.Attribute( " type " ).Value }).ToList(),
CollectivePropertyList
= CollectivePropertyList(c.Elements( " Property " ).Where(p => p.Attribute( " type " ).Value.Trim().ToLower() == " list " )),
RefenceList
= TopRefenceList(c.Elements( " Reference " ))
}).ToList
< DynamicEntity > ();
}

转载于:https://www.cnblogs.com/mxy1028/archive/2011/05/06/2039136.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值