Example #1
0
        /// <summary>
        ///     Returns null if not found in map file, otherwise result.Count > 1
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="propertyPath"></param>
        /// <param name="tagType"></param>
        /// <param name="getConstantValue"></param>
        /// <returns></returns>
        public List <string?>?GetFromMap(string?tag, string?propertyPath, string?tagType, Func <string, string>?getConstantValue = null)
        {
            string elementId = tag + propertyPath;

            if (elementId == @"" || Map.Count == 0)
            {
                return(null);
            }

            var values = Map.TryGetValue(elementId);

            if (values is not null)
            {
                if (values.Count == 1)
                {
                    values.Add("");
                }
                return(values);
            }

            var result = new List <string?> {
                elementId
            };

            if (String.IsNullOrEmpty(propertyPath))
            {
                return(null);
            }

            values = null;
            if (!string.IsNullOrEmpty(tagType))
            {
                values = Map.TryGetValue(tagType + TagTypeSeparator +
                                         GenericTag + propertyPath);
            }
            if (values is null)
            {
                values = Map.TryGetValue(GenericTag + propertyPath);
            }
            if (values is null)
            {
                return(null);
            }

            if (values.Count > 1)
            {
                for (var i = 1; i < values.Count; i++)
                {
                    string?v = SszQueryHelper.ComputeValueOfSszQueries(values[i], constant =>
                    {
                        if (String.Equals(constant, GenericTag, StringComparison.InvariantCultureIgnoreCase))
                        {
                            return(tag ?? @"");
                        }
                        if (getConstantValue != null)
                        {
                            return(getConstantValue(constant));
                        }
                        return(@"");
                    }, _csvDb);
                    result.Add(v ?? @"");
                }
            }
            else
            {
                result.Add("");
            }

            return(result);
        }
Example #2
0
        /// <summary>
        ///     Returns null if not found in map file, otherwise result.Count > 1
        /// </summary>
        /// <param name="elementId"></param>
        /// <param name="getConstantValue"></param>
        /// <returns></returns>
        public List <string?>?GetFromMap(string elementId, Func <string, string>?getConstantValue = null)
        {
            if (elementId == @"" || Map.Count == 0)
            {
                return(null);
            }

            var values = Map.TryGetValue(elementId);

            if (values is not null)
            {
                if (values.Count == 1)
                {
                    values.Add("");
                }
                return(values);
            }

            string?tag;
            string?propertyPath;
            string?tagType;

            var separatorIndex = elementId.LastIndexOf(TagAndPropertySeparator);

            if (separatorIndex > 0 && separatorIndex < elementId.Length - 1)
            {
                tag          = elementId.Substring(0, separatorIndex);
                propertyPath = elementId.Substring(separatorIndex);
                tagType      = GetTagType(tag);
            }
            else
            {
                tag          = elementId;
                propertyPath = null;
                tagType      = null;
            }

            if (String.IsNullOrEmpty(propertyPath))
            {
                return(null);
            }

            var result = new List <string?> {
                elementId
            };

            values = null;
            if (!string.IsNullOrEmpty(tagType))
            {
                values = Map.TryGetValue(tagType + TagTypeSeparator +
                                         GenericTag + propertyPath);
            }
            if (values is null)
            {
                values = Map.TryGetValue(GenericTag + propertyPath);
            }
            if (values is null)
            {
                return(null);
            }

            if (values.Count > 1)
            {
                for (var i = 1; i < values.Count; i++)
                {
                    string?v = SszQueryHelper.ComputeValueOfSszQueries(values[i],
                                                                       constant =>
                    {
                        if (String.Equals(constant, GenericTag, StringComparison.InvariantCultureIgnoreCase))
                        {
                            return(tag ?? @"");
                        }
                        if (getConstantValue != null)
                        {
                            return(getConstantValue(constant));
                        }
                        return(@"");
                    }
                                                                       , _csvDb);
                    result.Add(v ?? @"");
                }
            }
            else
            {
                result.Add("");
            }

            return(result);
        }