2023-08-01 15:35:11 +08:00
|
|
|
|
using MECF.Framework.Common.CommonData;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-08-01 15:35:11 +08:00
|
|
|
|
namespace Aitex.Core.Common.DeviceData.IoDevice.Base
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
[DataContract]
|
2023-08-08 00:36:56 +08:00
|
|
|
|
public abstract class XDataBase : NotifiableItem, IDeviceData
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-08 00:36:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新当前对象的属性。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
2023-04-13 11:51:03 +08:00
|
|
|
|
public void Update(IDeviceData data)
|
|
|
|
|
{
|
|
|
|
|
if (data == null)
|
|
|
|
|
return;
|
2023-08-01 15:35:11 +08:00
|
|
|
|
|
2023-04-13 11:51:03 +08:00
|
|
|
|
var targetProps = GetType().GetProperties()
|
|
|
|
|
.Where(prop => Attribute.IsDefined((MemberInfo)prop, typeof(DataMemberAttribute)));
|
2023-08-01 15:35:11 +08:00
|
|
|
|
|
2023-04-13 11:51:03 +08:00
|
|
|
|
var sourceProps = data.GetType().GetProperties()
|
|
|
|
|
.Where(prop => Attribute.IsDefined((MemberInfo)prop, typeof(DataMemberAttribute)));
|
2023-08-01 15:35:11 +08:00
|
|
|
|
|
2023-04-13 11:51:03 +08:00
|
|
|
|
Parallel.ForEach(targetProps, pi =>
|
|
|
|
|
{
|
|
|
|
|
var srcPi = sourceProps.FirstOrDefault(x => x.Name == pi.Name);
|
2023-08-01 15:35:11 +08:00
|
|
|
|
if (srcPi == null)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return;
|
2023-08-01 15:35:11 +08:00
|
|
|
|
|
2023-04-13 11:51:03 +08:00
|
|
|
|
pi.SetValue(this, srcPi.GetValue(data));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-01 15:35:11 +08:00
|
|
|
|
}
|