コード例 #1
0
        /// <summary>
        /// 这个不考虑效率,使用的时候应该保存返回的AutoKey以便再次使用。
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public AutoKey GetAutoKey(string name)
        {
            lock (this)
            {
                AutoKey tmp = new AutoKey(this, name, LocalId, LocalStep);
                if (map.TryGetValue(tmp, out var exist))
                {
                    return(exist);
                }

                map.Add(tmp, tmp);
                Dirty.GetAndSet(true);
                return(tmp);
            }
        }
コード例 #2
0
        internal AutoKeys(ByteBuffer os, int localInitValue, int localStep)
        {
            if (localStep <= 0 || localInitValue < 0 || localInitValue >= localStep)
            {
                throw new Exception("AutoKeys Invalid localInitValue or localStep");
            }

            LocalId   = localInitValue;
            LocalStep = localStep;

            if (null != os)
            {
                for (int n = os.ReadInt(); n > 0; --n)
                {
                    AutoKey autoKey = new AutoKey(this, os);
                    map.Add(autoKey, autoKey);
                }
            }
        }