Exemple #1
0
        /// <summary>
        ///     Finds the description in the domain that matches the specified <paramref name="value" />
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="value">The value.</param>
        /// <returns>Returns a <see cref="string" /> representing the name (or description) otherwise <c>null</c>.</returns>
        public static string GetDescription(this ICodedValueDomain source, object value)
        {
            if ((source == null) || (value == null) || Convert.IsDBNull(value))
            {
                return(null);
            }

            return((from entry in source.AsEnumerable() where entry.Value.Equals(value.ToString()) select entry.Key).FirstOrDefault());
        }
Exemple #2
0
        /// <summary>
        ///     Gets the corresponding domain value for the value.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="keyword">The criteria.</param>
        /// <param name="comparisonOperator">The comparison operator.</param>
        /// <returns>
        ///     The code value for the domain; otherwise the value parameter.
        /// </returns>
        private IEnumerable <string> GetDomainValues(IField field, string keyword, ComparisonOperator comparisonOperator)
        {
            List <string> items = new List <string>();

            if (_Subtypes.HasSubtype)
            {
                var values = _Subtypes.Subtypes.AsEnumerable();
                foreach (var subtype in values)
                {
                    if (_Subtypes.SubtypeFieldName.Equals(field.Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (this.AsOperatorMatch(keyword, subtype.Value, comparisonOperator))
                        {
                            var subtypeCode = subtype.Key.ToString(CultureInfo.InvariantCulture);
                            if (!items.Contains(subtypeCode))
                            {
                                items.Add(subtypeCode);
                            }
                        }
                    }
                    else
                    {
                        ICodedValueDomain codedValueDomain = _Subtypes.Domain[subtype.Key, field.Name] as ICodedValueDomain;
                        if (codedValueDomain != null)
                        {
                            foreach (var domain in codedValueDomain.AsEnumerable())
                            {
                                if (this.AsOperatorMatch(keyword, domain.Key, comparisonOperator))
                                {
                                    if (!items.Contains(domain.Value))
                                    {
                                        items.Add(domain.Value);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (items.Count == 0)
            {
                items.Add(keyword);
            }

            return(items);
        }
Exemple #3
0
        /// <summary>
        ///     Finds the value in the domain that matches the specified <paramref name="name" />
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="name">The name.</param>
        /// <param name="fallbackValue">The fallback value.</param>
        /// <returns>
        ///     Returns the value representing the name (or description) otherwise the fallback value is used.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">name</exception>
        public static TValue GetValue <TValue>(this ICodedValueDomain source, string name, TValue fallbackValue)
        {
            if (source == null)
            {
                return(fallbackValue);
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            object o = null;

            foreach (KeyValuePair <string, string> entry in source.AsEnumerable())
            {
                if (entry.Key.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    o = entry.Value;
                    break;
                }
            }
            return(TypeCast.Cast(o, fallbackValue));
        }
Exemple #4
0
 public void IDomain_AsEnumerable_Count_Equals_4()
 {
     Assert.AreEqual(4, _CodedValueDomain.AsEnumerable().Count());
 }