コード例 #1
0
        protected SortedSet <int> GetIncludedPropertyIndexes(int startIndex, int endIndex, List <MessageSerializedPropertyInfo> properties)
        {
            var includedPropertyIndexes = new SortedSet <int>();

            for (int index = startIndex; index <= endIndex; ++index)
            {
                MessageSerializedPropertyInfo propertyInfo             = properties[index];
                CalculatedFieldAttribute      calculatedFieldAttribute = GetApplicableCalculatedFieldAttribute <CalculatedFieldAttribute>(propertyInfo);
                if (calculatedFieldAttribute == null || !calculatedFieldAttribute.Exclude)
                {
                    includedPropertyIndexes.Add(index);
                }
            }

            return(includedPropertyIndexes);
        }
コード例 #2
0
        //protected int GetIndex(MessageSerializedPropertyInfo calculatorPropertyInfo, List<MessageSerializedPropertyInfo> properties, string fieldName, Func<CalculatedFieldAttribute, bool, Position> getPositionFunction)
        protected int GetIndex(
            MessageSerializedPropertyInfo calculatorPropertyInfo,
            List <MessageSerializedPropertyInfo> properties,
            string fieldName,
            Func <CalculatedFieldAttribute, Position> getPositionFunction,
            Func <CalculatedFieldResultAttribute, Position> getDefaultPositionFunction)
        {
            // Find the class that has the value defined and then get the index from that
            // If there isn't a class with the value defined use the default
            MessageSerializedPropertyInfo valuePropertyInfo = null;
            int indexToUse   = -1;
            int defaultIndex = -1;

            for (int currentIndex = 0; currentIndex < properties.Count; ++currentIndex)
            {
                MessageSerializedPropertyInfo propertyInfo             = properties[currentIndex];
                CalculatedFieldAttribute      calculatedFieldAttribute = GetApplicableCalculatedFieldAttribute <CalculatedFieldAttribute>(propertyInfo);
                Position position = calculatedFieldAttribute == null ? Position.Unspecified : getPositionFunction(calculatedFieldAttribute);
                if (calculatedFieldAttribute != null && position != Position.Unspecified)
                {
                    if (valuePropertyInfo != null)
                    {
                        throw new Exception($"For calculated field {Name}, property {propertyInfo.PropertyInfo.Name} specified {fieldName}, but {fieldName} was already specified on {valuePropertyInfo.PropertyInfo.Name}");
                    }

                    valuePropertyInfo = propertyInfo;
                    indexToUse        = GetIndexFromPosition(position, currentIndex, properties.Count);
                }

                if (propertyInfo == calculatorPropertyInfo)
                {
                    defaultIndex = GetIndexFromPosition(getDefaultPositionFunction(calculatedFieldAttribute as CalculatedFieldResultAttribute), currentIndex, properties.Count);
                }
            }

            return(valuePropertyInfo == null ? defaultIndex : indexToUse);
        }