コード例 #1
0
        public override EventBeanWriter GetWriter(string[] properties)
        {
            if (writablePropertyDescriptors == null) {
                InitializeWriters();
            }

            var allSimpleProps = true;
            var writers = new ObjectArrayEventBeanPropertyWriter[properties.Length];
            IList<int> indexes = new List<int>();
            var indexesPerProperty = PropertiesIndexes;

            for (var i = 0; i < properties.Length; i++) {
                var writerPair =
                    propertyWriters.Get(properties[i]);
                if (writerPair != null) {
                    writers[i] = writerPair.Second;
                    indexes.Add(indexesPerProperty.Get(writerPair.First.PropertyName));
                }
                else {
                    writers[i] = (ObjectArrayEventBeanPropertyWriter) GetWriter(properties[i]);
                    if (writers[i] == null) {
                        return null;
                    }

                    allSimpleProps = false;
                }
            }

            if (allSimpleProps) {
                var propertyIndexes = CollectionUtil.IntArray(indexes);
                return new ObjectArrayEventBeanWriterSimpleProps(propertyIndexes);
            }

            return new ObjectArrayEventBeanWriterPerProp(writers);
        }
コード例 #2
0
        private void InitializeWriters()
        {
            IList<EventPropertyDescriptor> writeableProps = new List<EventPropertyDescriptor>();
            IDictionary<string, Pair<EventPropertyDescriptor, ObjectArrayEventBeanPropertyWriter>> propertyWritersMap =
                new Dictionary<string, Pair<EventPropertyDescriptor, ObjectArrayEventBeanPropertyWriter>>();
            foreach (var prop in PropertyDescriptors) {
                writeableProps.Add(prop);
                var propertyName = prop.PropertyName;
                if (!PropertiesIndexes.TryGetValue(prop.PropertyName, out var index)) {
                    continue;
                }

                var eventPropertyWriter = new ObjectArrayEventBeanPropertyWriter(index);
                propertyWritersMap.Put(
                    propertyName,
                    new Pair<EventPropertyDescriptor, ObjectArrayEventBeanPropertyWriter>(prop, eventPropertyWriter));
            }

            propertyWriters = propertyWritersMap;
            writablePropertyDescriptors = writeableProps.ToArray();
        }