+ Mapper: 增加对象映射类
This commit is contained in:
parent
768e8352e0
commit
6e74477a84
Binary file not shown.
Binary file not shown.
@ -29,20 +29,6 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
public static class GDI
|
public static class GDI
|
||||||
{
|
{
|
||||||
public static PointF AzRange(this PointF center, float range, float az, float xOffset = 0, float yOffset = 0)
|
|
||||||
{
|
|
||||||
float x = (float)(range * 1.0f * Math.Sin(az * Math.PI / 180));
|
|
||||||
float y = (float)(range * 1.0f * Math.Cos(az * Math.PI / 180));
|
|
||||||
return new PointF(center.X + xOffset + x, center.Y + yOffset - y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PointF AzRange(this Point center, float range, float az, float xOffset = 0, float yOffset = 0)
|
|
||||||
{
|
|
||||||
float x = (float)(range * 1.0f * Math.Sin(az * Math.PI / 180));
|
|
||||||
float y = (float)(range * 1.0f * Math.Cos(az * Math.PI / 180));
|
|
||||||
return new PointF(center.X + xOffset + x, center.Y + yOffset - y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 点是否在区域内
|
/// 点是否在区域内
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
46
SunnyUI/Static/UMapper.cs
Normal file
46
SunnyUI/Static/UMapper.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Sunny.UI
|
||||||
|
{
|
||||||
|
public static class MapperEx
|
||||||
|
{
|
||||||
|
private static void Mapper<T>(T source, T dest)
|
||||||
|
{
|
||||||
|
var listSource = source.GetType().GetNeedProperties().ToDictionary(prop => prop.Name);
|
||||||
|
var listDest = source.GetType().GetNeedProperties().ToDictionary(prop => prop.Name);
|
||||||
|
|
||||||
|
foreach (var item in listDest)
|
||||||
|
{
|
||||||
|
if (listSource.ContainsKey(item.Key))
|
||||||
|
{
|
||||||
|
var sourceInfo = listSource[item.Key];
|
||||||
|
object sourceValue = sourceInfo.GetValue(source, null);
|
||||||
|
Type sourceType = sourceInfo.PropertyType;
|
||||||
|
|
||||||
|
Type destType = item.Value.PropertyType;
|
||||||
|
var destInfo = item.Value;
|
||||||
|
|
||||||
|
if (sourceType.IsValueType)
|
||||||
|
{
|
||||||
|
destInfo.SetValue(dest, sourceValue, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MapperTo<T>(this T source, T dest)
|
||||||
|
{
|
||||||
|
Mapper(source, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MapperFrom<T>(this T dest, T source)
|
||||||
|
{
|
||||||
|
Mapper(source, dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user