using System.Reflection;
public static string Join<T>(List<T> pListForJoin, string pPropertyName, string pSeparator, string pEnclosed)
{
if (pListForJoin.Count > 0)
{
List<Object> ltgAfterFilter = new List<Object>();
for (int i = 0; i < pListForJoin.Count; i++)
{
foreach (PropertyInfo p in pListForJoin[i].GetType().GetProperties())
{
if (p.Name.ToUpper().Equals(pPropertyName.ToUpper()))
{
if (p.GetValue(pListForJoin[i]) == null)
{
}
else
{
ltgAfterFilter.Add(p.GetValue(pListForJoin[i]));
break;
}
}
}
//没有get;set;时使用的
foreach (FieldInfo f in pListForJoin[i].GetType().GetFields())
{
if (f.Name.ToUpper().Equals(pPropertyName.ToUpper()))
{
if (f.GetValue(pListForJoin[i]) == null)
{
}
else
{
ltgAfterFilter.Add(f.GetValue(pListForJoin[i]));
break;
}
}
}
}
return Join(ltgAfterFilter, pSeparator, pEnclosed);
}
else
{
return "";
}
}