示例#1
0
        protected virtual byte ResolvePid <T>()
            where T : class, IOBDData, new()
        {
            byte pid;

            if (!PidCache.TryGetValue(typeof(T), out pid))
            {
                T data = Activator.CreateInstance <T>();
                pid = data.PID;
                PidCache.Add(typeof(T), pid);
                DataTypeCache.Add(pid, typeof(T));
            }

            return(pid);
        }
示例#2
0
        protected virtual byte AddToPidCache(Type obdDataType)
        {
            IOBDData data = (IOBDData)Activator.CreateInstance(obdDataType);

            if (data == null)
            {
                throw new ArgumentException("Has to implement IOBDData", nameof(obdDataType));
            }

            byte pid = data.PID;

            PidCache.Add(obdDataType, pid);
            DataTypeCache.Add(pid, obdDataType);

            return(pid);
        }