123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- 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<T>
- {
- 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<Type, object> ProtocolObjs = new ConcurrentDictionary<Type, object>();
- public bool HasProtocol(Type type)
- {
- return Protocols.HasProtocol(type, Code);
- //return ProtocolObjs.ContainsKey(type);
- }
- public bool HasProtocol<T>()
- {
- return HasProtocol(typeof(T));
- }
- public T Protocol<T>()
- {
- 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<T> : EntityEx<Device>
- {
- public T Data { get; set; }
- public Device(Device device) : base(device)
- {
- Data = Entity.Protocol<T>();
- }
- public override string ToString()
- {
- return Entity.Code;
- }
- }
- public class Device<T, T2> : Device<T>
- {
- public T2 Data2 { get; set; }
- public Device(Device device) : base(device)
- {
- Data2 = Entity.Protocol<T2>();
- }
- }
- public class Device<T, T2, T3> : Device<T, T2>
- {
- public T3 Data3 { get; set; }
- public Device(Device device) : base(device)
- {
- Data3 = Entity.Protocol<T3>();
- }
- }
- public class Device<T, T2, T3, T4> : Device<T, T2, T3>
- {
- public T4 Data4 { get; set; }
- public Device(Device device) : base(device)
- {
- Data4 = Entity.Protocol<T4>();
- }
- }
- public class Device<T, T2, T3, T4, T5> : Device<T, T2, T3, T4>
- {
- public T5 Data5 { get; set; }
- public Device(Device device) : base(device)
- {
- Data5 = Entity.Protocol<T5>();
- }
- }
- public class Device<T, T2, T3, T4, T5, T6> : Device<T, T2, T3, T4, T5>
- {
- public T6 Data6 { get; set; }
- public Device(Device device) : base(device)
- {
- Data6 = Entity.Protocol<T6>();
- }
- }
- }
|