using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WCS.Core { public class EntityEx { public T Entity { get; private set; } public EntityEx(T ent) { this.Entity = ent; } } public class Device { public string Code { get; set; } = ""; public World World { get; set; } ConcurrentDictionary ProtocolObjs = new ConcurrentDictionary(); public bool HasProtocol(Type type) { return Protocols.HasProtocol(type, Code); //return ProtocolObjs.ContainsKey(type); } public bool HasProtocol() { return HasProtocol(typeof(T)); } public T Protocol() { return (T)Protocol(typeof(T)); } public object Protocol(Type protocolType) { if (!ProtocolObjs.ContainsKey(protocolType)) { var type = typeof(Generator<,>); type = type.MakeGenericType(protocolType, Configs.ProtocolProxyBaseType); var m = type.GetMethod("Create", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); var info = Protocols.Get(protocolType, Code); var obj = m.Invoke(null, new object[] { new object[] { this, info, protocolType } }); ProtocolObjs[protocolType] = obj; } return ProtocolObjs[protocolType]; } public override string ToString() { return Code; } } public class Device : EntityEx { public T Data { get; set; } public Device(Device device) : base(device) { Data = Entity.Protocol(); } public override string ToString() { return Entity.Code; } } public class Device : Device { public T2 Data2 { get; set; } public Device(Device device) : base(device) { Data2 = Entity.Protocol(); } } public class Device : Device { public T3 Data3 { get; set; } public Device(Device device) : base(device) { Data3 = Entity.Protocol(); } } public class Device : Device { public T4 Data4 { get; set; } public Device(Device device) : base(device) { Data4 = Entity.Protocol(); } } public class Device : Device { public T5 Data5 { get; set; } public Device(Device device) : base(device) { Data5 = Entity.Protocol(); } } public class Device : Device { public T6 Data6 { get; set; } public Device(Device device) : base(device) { Data6 = Entity.Protocol(); } } }