示例#1
0
        private VariantPropertyGetterRow AddType(EventType eventType)
        {
            var newKnownTypes = (EventType[])ResizeArray(_knownTypes, _knownTypes.Length + 1);

            newKnownTypes[newKnownTypes.Length - 1] = eventType;

            // create getters
            var getters = new EventPropertyGetter[_properties.Count];

            for (int i = 0; i < _properties.Count; i++)
            {
                getters[i] = eventType.GetGetter(_properties[i]);
            }

            var row = new VariantPropertyGetterRow(eventType, getters);

            var newAllGetters = new Dictionary <EventType, VariantPropertyGetterRow>();

            newAllGetters.PutAll(_allGetters);
            newAllGetters.Put(eventType, row);

            // overlay volatiles
            _knownTypes = newKnownTypes;
            _allGetters = newAllGetters;

            return(row);
        }
示例#2
0
        /// <summary>Fast lookup of a getter for a property and type. </summary>
        /// <param name="assignedPropertyNumber">number of property to use as index</param>
        /// <param name="eventType">type of underlying event</param>
        /// <returns>getter</returns>
        public EventPropertyGetter GetGetter(int assignedPropertyNumber, EventType eventType)
        {
            VariantPropertyGetterRow lastGetters = _lastUsedGetters;

            if ((lastGetters != null) && (lastGetters.EventType == eventType))
            {
                return(lastGetters.GetterPerProp[assignedPropertyNumber]);
            }

            VariantPropertyGetterRow row = _allGetters.Get(eventType);

            // newly seen type (Using ANY type variance or as a subtype of an existing variance type)
            // synchronized add, if added twice then that is ok too
            if (row == null)
            {
                lock (this)
                {
                    row = _allGetters.Get(eventType);
                    if (row == null)
                    {
                        row = AddType(eventType);
                    }
                }
            }

            EventPropertyGetter getter = row.GetterPerProp[assignedPropertyNumber];

            _lastUsedGetters = row;
            return(getter);
        }
        private VariantPropertyGetterRow AddType(EventType eventType)
        {
            var newKnownTypes = (EventType[]) ResizeArray(knownTypes, knownTypes.Length + 1);
            newKnownTypes[newKnownTypes.Length - 1] = eventType;

            // create getters
            IDictionary<string, EventPropertyGetter> getters = new Dictionary<string, EventPropertyGetter>();
            for (var i = 0; i < properties.Count; i++) {
                var propertyName = properties[i];
                var getter = eventType.GetGetter(propertyName);
                getters.Put(propertyName, getter);
            }

            var row = new VariantPropertyGetterRow(eventType, getters);

            IDictionary<EventType, VariantPropertyGetterRow> newAllGetters =
                new Dictionary<EventType, VariantPropertyGetterRow>();
            newAllGetters.PutAll(allGetters);
            newAllGetters.Put(eventType, row);

            // overlay volatiles
            knownTypes = newKnownTypes;
            allGetters = newAllGetters;

            return row;
        }
        /// <summary>
        ///     Adds the getters for a property that is identified by a property number which indexes into array of getters per
        ///     type.
        /// </summary>
        /// <param name="propertyName">to add</param>
        public void AddGetters(string propertyName)
        {
            foreach (var type in knownTypes) {
                var getter = type.GetGetter(propertyName);

                var row = allGetters.Get(type);
                if (row == null) {
                    lock (this) {
                        row = new VariantPropertyGetterRow(type, new Dictionary<string, EventPropertyGetter>());
                        allGetters.Put(type, row);
                    }
                }

                row.AddGetter(propertyName, getter);
            }

            properties.Add(propertyName);
        }
示例#5
0
        /// <summary>Adds the getters for a property that is identified by a property number which indexes into array of getters per type. </summary>
        /// <param name="assignedPropertyNumber">number of property</param>
        /// <param name="propertyName">to add</param>
        public void AddGetters(int assignedPropertyNumber, String propertyName)
        {
            foreach (EventType type in _knownTypes)
            {
                EventPropertyGetter getter = type.GetGetter(propertyName);

                VariantPropertyGetterRow row = _allGetters.Get(type);
                if (row == null)
                {
                    using (_iLock.Acquire())
                    {
                        row = new VariantPropertyGetterRow(type, new EventPropertyGetter[assignedPropertyNumber + 1]);
                        _allGetters.Put(type, row);
                    }
                }
                row.AddGetter(assignedPropertyNumber, getter);
            }
            _properties.Add(propertyName);
        }
        /// <summary>
        ///     Fast lookup of a getter for a property and type.
        /// </summary>
        /// <param name="propertyName">property name</param>
        /// <param name="eventType">type of underlying event</param>
        /// <returns>getter</returns>
        public EventPropertyGetter GetGetter(
            string propertyName,
            EventType eventType)
        {
            var lastGetters = lastUsedGetters;
            if (lastGetters != null && lastGetters.EventType == eventType) {
                var getterInner = lastGetters.GetterPerProp.Get(propertyName);
                if (getterInner == null) {
                    getterInner = eventType.GetGetter(propertyName);
                    lastGetters.AddGetter(propertyName, getterInner);
                }

                return getterInner;
            }

            var row = allGetters.Get(eventType);

            // newly seen type (Using ANY type variance or as a subtype of an existing variance type)
            // synchronized add, if added twice then that is ok too
            if (row == null) {
                lock (this) {
                    row = allGetters.Get(eventType);
                    if (row == null) {
                        row = AddType(eventType);
                    }
                }
            }

            var getter = row.GetterPerProp.Get(propertyName);
            lastUsedGetters = row;

            if (getter == null) {
                getter = eventType.GetGetter(propertyName);
                row.AddGetter(propertyName, getter);
            }

            return getter;
        }