工行MySQL_工行ICBC_WAPB_B2C支付接口

public classXmlHelper

{///

///根据模型生成一个xml,其中不包括类名///

/// 模型

/// 属性值为空,xml生成是否返回该属性

///

public static StringBuilder ModelToXml(objectModel, Flag flag)

{

StringBuilder Xml= newStringBuilder();

Type t=Model.GetType();

System.Reflection.PropertyInfo[] properties=t.GetProperties();foreach (var item inproperties)

{var PropertiesValue = item.GetValue(Model, null);string PropertiesName =item.Name;if (PropertiesValue == null || string.IsNullOrEmpty(PropertiesValue.ToString()))

{if (flag==Flag.Y)

{

Xml.AppendFormat("{1}{0}>", PropertiesName, PropertiesValue);

}

}else{

Xml.AppendFormat("{1}{0}>", PropertiesName, PropertiesValue);

}

}returnXml;

}///

///根据模型生成一个xml,其他不包括类名///

/// 模型

/// 属性值为空,xml生成是否返回该属性

/// 对属性名称排序/可选(升序、降序)

///

public static StringBuilder ModelToXml(object Model, Flag flag,Sort sort=Sort.Asc)

{

StringBuilder Xml= newStringBuilder();

Type t=Model.GetType();

System.Reflection.PropertyInfo[] properties=t.GetProperties();

Dictionary dic = new Dictionary();foreach (var item inproperties)

{var PropertiesValue = item.GetValue(Model, null);string PropertiesName =item.Name;

dic.Add(PropertiesName, PropertiesValue);

}//对属性排序

var SortList = sort == Sort.Asc ? dic.OrderBy(o => o.Key) : dic.OrderByDescending(o =>o.Key);foreach (var item inSortList)

{if (item.Value == null || string.IsNullOrEmpty(item.Value.ToString()))

{if (flag ==Flag.Y)

{

Xml.AppendFormat("{1}{0}>", item.Key, item.Value);

}

}else{

Xml.AppendFormat("{1}{0}>", item.Key, item.Value);

}

}returnXml;

}///

///根据模型生成一个xml,其他不包括类名///

/// 模型

/// 属性值为空,xml生成是否返回该属性

/// 对属性名称排序/可选(升序、降序)

/// 父节点名称

///

public static StringBuilder ModelToXml(object Model, Flag flag, Sort sort,stringRootName)

{

StringBuilder Xml= newStringBuilder();

Type t=Model.GetType();

System.Reflection.PropertyInfo[] properties=t.GetProperties();

Dictionary dic = new Dictionary();

Xml.AppendFormat("",RootName);foreach (var item inproperties)

{var PropertiesValue = item.GetValue(Model, null);string PropertiesName =item.Name;

dic.Add(PropertiesName, PropertiesValue);

}//对属性排序

var SortList = sort == Sort.Asc ? dic.OrderBy(o => o.Key) : dic.OrderByDescending(o =>o.Key);foreach (var item inSortList)

{if (item.Value == null || string.IsNullOrEmpty(item.Value.ToString()))

{if (flag ==Flag.Y)

{

Xml.AppendFormat("{1}{0}>", item.Key, item.Value);

}

}else{

Xml.AppendFormat("{1}{0}>", item.Key, item.Value);

}

}

Xml.AppendFormat("{0}>", RootName);returnXml;

}

}///

///枚举///

public enumFlag

{///

///是///

Y,///

///否///

N

};///

///排序///

public enumSort

{///

///升序///

Asc,///

///降序///

Desc

};public classToo

{//编码内容

public static string Base64Encode(stringstr)

{byte[] b =System.Text.Encoding.Default.GetBytes(str);//转成Base64形式的System.String

returnConvert.ToBase64String(b);

}//解码内容

public static string Base64Decode(stringstr)

{byte[] outputb =Convert.FromBase64String(str);string orgStr =Encoding.Default.GetString(outputb);returnorgStr;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值