Пример #1
0
        public static IEnumerable <KeyValuePair <string, string> > GetRichDescriptions(this IAnalysisSet set, string prefix = null, bool useLongDescription = false, string unionPrefix = null, string unionSuffix = null)
        {
            var items = new List <KeyValuePair <string, string> >();

            foreach (var d in (useLongDescription ? set.GetDescriptions() : set.GetShortDescriptions()))
            {
                items.Add(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Type, d));
                items.Add(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Comma, ", "));
            }

            if (items.Count == 2)
            {
                items.RemoveAt(1);
            }

            if (items.Count > 2)
            {
                if (!string.IsNullOrEmpty(unionPrefix))
                {
                    items.Insert(0, new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, unionPrefix));
                }
                if (!string.IsNullOrEmpty(unionSuffix))
                {
                    items.Add(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, unionSuffix));
                }
            }

            if (items.Count > 0 && !string.IsNullOrEmpty(prefix))
            {
                items.Insert(0, new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, prefix));
            }

            return(items);
        }
        public static IEnumerable <KeyValuePair <string, string> > GetRichDescriptions(this IAnalysisSet set, string prefix = null, bool useLongDescription = false, string unionPrefix = null, string unionSuffix = null, bool alwaysUsePrefixSuffix = false, string defaultIfEmpty = null)
        {
            var items     = new List <KeyValuePair <string, string> >();
            int itemCount = 0;

            foreach (var d in (useLongDescription ? set.GetDescriptions() : set.GetShortDescriptions()))
            {
                var desc = !string.IsNullOrEmpty(d) ? d : defaultIfEmpty;
                items.Add(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Type, desc));
                items.Add(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Comma, ", "));
                itemCount += 1;
            }

            if (itemCount == 1)
            {
                items.RemoveAt(items.Count - 1);
            }

            if (alwaysUsePrefixSuffix || itemCount >= 2)
            {
                if (!string.IsNullOrEmpty(unionPrefix))
                {
                    items.Insert(0, new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, unionPrefix));
                }
                if (!string.IsNullOrEmpty(unionSuffix))
                {
                    items.Add(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, unionSuffix));
                }
            }

            if (itemCount > 0 && !string.IsNullOrEmpty(prefix))
            {
                items.Insert(0, new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, prefix));
            }

            if (items.Count == 0 && !string.IsNullOrEmpty(defaultIfEmpty))
            {
                items.Add(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, defaultIfEmpty));
            }

            return(items);
        }