44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MyCode.Project.Domain.Message.Response.Common
|
|
{
|
|
public class Format
|
|
{
|
|
/// <summary>
|
|
/// 格式化数据样式
|
|
/// </summary>
|
|
public static void FormatValues<T>(T h)
|
|
{
|
|
PropertyInfo[] proFEntity = h.GetType().GetProperties();
|
|
foreach (PropertyInfo pi in proFEntity)
|
|
{
|
|
decimal? NewValue = 0m;
|
|
string NewValueTypeName = NewValue.GetType().Name;
|
|
string PiTypeName = pi.PropertyType.Name;
|
|
var item = pi.PropertyType.GenericTypeArguments.FirstOrDefault();
|
|
if (NewValue.GetType().Name.Equals(pi.PropertyType.Name) || (item != null && item.Name == NewValueTypeName))
|
|
{
|
|
var value = (decimal?)pi.GetValue(h);
|
|
if (value.HasValue)
|
|
{ }
|
|
try
|
|
{
|
|
pi.SetValue(h, Math.Round(value.Value, 2, MidpointRounding.AwayFromZero), null);
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|