分支自 SuZhouGuanHong/TaiYuanTaiZhong

WMS
dengjunjie
2023-12-13 d772a6cddc8ed656a2cb5604fc02f6e891db546e
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
using System.IO;
 
namespace WIDESEA_Core.Utilities
{
  /// <summary>
  /// 动态属性Bag
  /// </summary>
  public class DynamicPropertyBag : DynamicObject
  {
    private Dictionary<string, object> storage = new Dictionary<string, object>();
 
    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
      if (storage.ContainsKey(binder.Name))
      {
        result = storage[binder.Name];
        return true;
      }
      result = null;
      return false;
    }
 
    public override bool TrySetMember(SetMemberBinder binder, object value)
    {
      string key = binder.Name;
      if (storage.ContainsKey(key))
        storage[key] = value;
      else
        storage.Add(key, value);
      return true;
    }
 
    public override string ToString()
    {
      StringWriter message = new StringWriter();
      foreach (var item in storage)
        message.WriteLine("{0}:\t{1}", item.Key, item.Value);
      return message.ToString();
    }
  }
}