using System;
|
using System.Reflection;
|
|
namespace PdmSwPlugin.Common.Util
|
{
|
public static class BeanUtil
|
{
|
public static FieldInfo[] GetTypeFields(Type type, BindingFlags bindingAttr) {
|
FieldInfo[] fields = type.GetFields(bindingAttr);
|
return fields;
|
}
|
|
public static PropertyInfo[] GetTypeProperties(Type type, BindingFlags bindingAttr) {
|
PropertyInfo[] fields = type.GetProperties(bindingAttr);
|
return fields;
|
}
|
|
public static void CopyPropertyIgnoreNull<T>(T source, T target)
|
{
|
if (source == null)
|
{
|
return;
|
}
|
Type type = source.GetType();
|
if (source is string || type.IsValueType)
|
{
|
return;
|
}
|
|
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
|
foreach (FieldInfo field in fields)
|
{
|
object value = field.GetValue(source);
|
if (value != null)
|
{
|
field.SetValue(target, field.GetValue(source));
|
}
|
|
}
|
return;
|
}
|
|
}
|
}
|