VMBase.cs
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using RCS.Model.Entity;
namespace RCS.Model.Comm
{
public abstract class VMBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public virtual void SetProp(ConcurrentBag<Base_EquipmentProp> props)
{
if (props == null)
{
return;
}
foreach (var item in GetType().GetProperties())
{
var temp = props.FirstOrDefault(t => t.Code == item.Name);
if (temp != null)
{
item.SetValue(this, temp.Value);
//SetPropertyValue(item, temp.Value);
}
}
}
public void SetPropertyValue(PropertyInfo propertyInfo, object value)
{
if (propertyInfo != null)
{
Type propertyType = propertyInfo.PropertyType;
object convertedValue = Convert.ChangeType(value, propertyType);
propertyInfo.SetValue(this, convertedValue);
}
}
}
}