Beispiel #1
0
        /// <summary>
        /// create a empty entry into the DNObjectsCollection
        /// </summary>
        /// <param name="dnType">the type of the object that will be saved in the entry</param>
        /// <param name="currentTaskDNEventsNames">comma-delimited string of events that are handled for the .net variable in the task containing the variable</param>
        /// <returns>created key</returns>
        internal int CreateEntry(Type dnType, String currentTaskDNEventsNames)
        {
            int key = 0;
            DNObjectsCollectionEntry entry = new DNObjectsCollectionEntry(dnType, null, currentTaskDNEventsNames);

            lock (_objectsLock)
            {
                for (int i = 0; i < _objects.Count; i++)
                {
                    if (_objects[i] == null)
                    {
                        _objects[i] = entry;
                        key         = i + 1; //the class returns 1-based keys (key 0 indicates no key)
                        break;
                    }
                }
                if (key == 0)
                {
                    _objects.Add(entry);
                    key = _objects.Count;
                }

                Debug.Assert(key > 0 && key <= _objects.Count); //the class returns 1-based keys (key 0 indicates no key)
            }
            return(key);
        }
Beispiel #2
0
        /// <summary>
        /// updates the existing object in DNObjectsCollection
        /// Note: this method shall not create a new entry if there exists no entry at 'key'.
        /// it will always replace the existing object entry at 'key'.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="obj"></param>
        public void Update(int key, Object obj)
        {
            lock (_objectsLock)
            {
                Debug.Assert(key > 0 && key <= _objects.Count); //the class returns 1-based keys (key 0 indicates no key)

                // cast the given object into the type that was set to the entry when created,
                // and save it in the entry.
                DNObjectsCollectionEntry entry = _objects[key - 1];
                if (obj != null && entry.DNType != null)
                {
                    obj = ReflectionServices.DynCast(obj, entry.DNType);
                }
                entry.DNObj = obj;
            }
        }