You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

70 lines
2.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace NFine.Application.DHAY
{
public static class ConvertExt
{
#region 文本转换
public static string ToStringExt(this object data)
{
return data == null ? string.Empty : data.ToString();
}
public static bool IsNullOrEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
//public static string ToStringExt(this IConvertHelper convert, object data)
//{
// return ToStringExt(data);
//}
#endregion
public static To Mapping<From, To>(From model)
{
To result = Activator.CreateInstance<To>();
foreach (PropertyInfo info in typeof(To).GetProperties())
{
PropertyInfo pro = typeof(From).GetProperty(info.Name);
if (pro != null && pro.PropertyType == info.PropertyType)
info.SetValue(result, pro.GetValue(model));
}
return result;
}
public static To Mapping<From, To>(From model, To result)
{
foreach (PropertyInfo info in typeof(To).GetProperties())
{
PropertyInfo pro = typeof(From).GetProperty(info.Name);
if (pro != null && pro.PropertyType == info.PropertyType)
{
var value = pro.GetValue(model);
if (value == null)
{
continue;
}
info.SetValue(result, value);
}
}
return result;
}
}
public static class CommonHelper
{
public static string GetBaseUrl(Uri url)
{
return new StringBuilder()
.Append(url.Scheme)
.Append("://")
.Append(url.Authority)
.ToString();
}
}
}