internal static string CodedValueNameLookup(string field, object generic, CodedValueSources codedValueSources)
        {
#if SILVERLIGHT
            PropertyInfo fieldProperty = generic.GetType().GetProperty(field);
            if (fieldProperty == null)
            {
                return("");
            }

            var code = fieldProperty.GetValue(generic, null);
#else
            var code = generic is Graphic ? (generic as Graphic).Attributes[field] : null;
#endif
            if (code == null)
            {
                return("");
            }

            foreach (CodedValueSource codedValueSource in codedValueSources)
            {
                if (codedValueSource.Code != null && code != null)
                {
                    if (codedValueSource.Code.ToString() == code.ToString())
                    {
                        return(codedValueSource.DisplayName);
                    }
                }
                else if (codedValueSource.Code == null && code == null)
                {
                    return(codedValueSource.DisplayName);
                }
            }
            return(code.ToString());
        }
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>
        /// The value to be passed to the target dependency property.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null || string.IsNullOrEmpty(Field) || value == null)
            {
                return("");
            }

#if SILVERLIGHT
            PropertyInfo fieldProperty = value.GetType().GetProperty(Field);
            if (fieldProperty == null)
            {
                return("");
            }

            var code = fieldProperty.GetValue(value, null);
#else
            var code = value;
#endif
            if (code == null)
            {
                return("");
            }

            CodedValueSources codedValueSources = parameter as CodedValueSources;
            if (codedValueSources != null)
            {
                CodedValueSource codedValueSource = codedValueSources.FirstOrDefault(x => x.Code != null && x.Code.ToString() == code.ToString());
                if (codedValueSource != null)
                {
                    return(codedValueSource.DisplayName);
                }
            }

            return("");
        }
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>
        /// The value to be passed to the target dependency property.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null || parameter.ToString() == "")
            {
                return("");
            }

            CodedValueSources codedValueSources = parameter as CodedValueSources;

            if (codedValueSources != null)
            {
                foreach (CodedValueSource codedValueSource in codedValueSources)
                {
                    if (codedValueSource.Code != null && value != null)
                    {
                        if (codedValueSource.Code.ToString() == value.ToString())
                        {
                            return(codedValueSource.DisplayName);
                        }
                    }
                    else if (codedValueSource.Code == null && value == null)
                    {
                        return(codedValueSource.DisplayName);
                    }
                }
            }

            return("");
        }
Exemple #4
0
        internal static object CodedValueCodeLookup(string field, object generic, CodedValueSources codedValueSources)
        {
            bool   isGraphic = (generic is Graphic);
            object code      = null;

            if (isGraphic)
            {
                code = ((Graphic)generic).Attributes[field];
            }
#if SILVERLIGHT
            else
            {
                PropertyInfo fieldProperty = generic.GetType().GetProperty(field);
                if (fieldProperty == null)
                {
                    return(null);
                }

                code = fieldProperty.GetValue(generic, null);
            }
#endif
            if (code == null)
            {
                return(null);
            }

            return(code);
        }
Exemple #5
0
        /// <summary>
        /// Returns a CodedValueSources object constructed form the CodedValueDomain value.
        /// </summary>
        /// <param name="field">The field to make a CodedValueSource from.</param>
        /// <returns>The CodedValueSources object used for a code to value lookup.</returns>
        internal static CodedValueSources BuildCodedValueSource(Field field)
        {
            CodedValueDomain  codedValueDomain  = field.Domain as CodedValueDomain;
            CodedValueSources codedValueSources = null;

            if (codedValueDomain != null)
            {
                foreach (KeyValuePair <object, string> codedValue in codedValueDomain.CodedValues)
                {
                    if (codedValueSources == null)
                    {
                        codedValueSources = new CodedValueSources();
                        if (field.Nullable)
                        {
                            CodedValueSource nullableSource = new CodedValueSource()
                            {
                                Code = null, DisplayName = " "
                            };
                            codedValueSources.Add(nullableSource);
                        }
                    }
                    codedValueSources.Add(new CodedValueSource()
                    {
                        Code = codedValue.Key, DisplayName = codedValue.Value
                    });
                }
            }
            return(codedValueSources);
        }
Exemple #6
0
        /// <summary>
        /// Returns CodedValueSources that make up the display text of each value of the TypeIDField.
        /// </summary>
        /// <param name="field">TypeIDField</param>
        /// <param name="layerInfo">FeatureLayerInof used to construct the CodedValueSources from the FeatureTypes.</param>
        /// <returns>CodedValueSoruces that contain code an value matches to all possible TypeIDField values.</returns>
        internal static CodedValueSources BuildTypeIDCodedValueSource(Field field, FeatureLayerInfo layerInfo)
        {
            CodedValueSources codedValueSources = null;

            foreach (KeyValuePair <object, FeatureType> kvp in layerInfo.FeatureTypes)
            {
                if (kvp.Key == null)
                {
                    continue;
                }
                string           name             = (kvp.Value != null && kvp.Value.Name != null) ? kvp.Value.Name : "";
                CodedValueSource codedValueSource = new CodedValueSource()
                {
                    Code = kvp.Key, DisplayName = name
                };
                if (codedValueSources == null)
                {
                    codedValueSources = new CodedValueSources();
                    if (field.Nullable)
                    {
                        CodedValueSource nullableSource = new CodedValueSource()
                        {
                            Code = null, DisplayName = " "
                        };
                        codedValueSources.Add(nullableSource);
                    }
                }
                codedValueSources.Add(codedValueSource);
            }
            return(codedValueSources);
        }
Exemple #7
0
        /// <summary>
        /// Builds a DynamicCodedValueSource object used to lookup display value.
        /// </summary>
        /// <param name="field">The field to build DynamicCodedValueSource for</param>
        /// <param name="layerInfo">The FeatureLayerInfo used to lookup all the coded value domains </param>
        /// <returns>DynamicCodedValueSource which is a collection of coded value domain values for a field.</returns>
        internal static DynamicCodedValueSource BuildDynamicCodedValueSource(Field field, FeatureLayerInfo layerInfo)
        {
            DynamicCodedValueSource dynamicCodedValueSource = null;

            foreach (object key in layerInfo.FeatureTypes.Keys)
            {
                FeatureType featureType = layerInfo.FeatureTypes[key];
                if (featureType.Domains.ContainsKey(field.Name))
                {
                    if (dynamicCodedValueSource == null)
                    {
                        dynamicCodedValueSource = new DynamicCodedValueSource();
                    }

                    CodedValueDomain codedValueDomain = featureType.Domains[field.Name] as CodedValueDomain;
                    if (codedValueDomain != null)
                    {
                        CodedValueSources codedValueSources = null;
                        foreach (KeyValuePair <object, string> kvp in codedValueDomain.CodedValues)
                        {
                            if (codedValueSources == null)
                            {
                                codedValueSources = new CodedValueSources();
                                if (field.Nullable)
                                {
                                    CodedValueSource nullableSource = new CodedValueSource()
                                    {
                                        Code = null, DisplayName = " "
                                    };
                                    codedValueSources.Add(nullableSource);
                                }
                            }

                            codedValueSources.Add(new CodedValueSource()
                            {
                                Code = kvp.Key, DisplayName = kvp.Value
                            });
                        }
                        if (codedValueSources != null)
                        {
                            if (dynamicCodedValueSource == null)
                            {
                                dynamicCodedValueSource = new DynamicCodedValueSource();
                            }

                            dynamicCodedValueSource.Add(featureType.Id, codedValueSources);
                        }
                    }
                }
            }
            return(dynamicCodedValueSource);
        }
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>
        /// The value to be passed to the target dependency property.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null)
            {
                return(null);
            }

            CodedValueSources codedValueSources = parameter as CodedValueSources;

            if (codedValueSources != null)
            {
                return(codedValueSources);
            }

            return("");
        }
        internal static object CodedValueCodeLookup(string field, object generic, CodedValueSources codedValueSources)
        {
#if SILVERLIGHT
            PropertyInfo fieldProperty = generic.GetType().GetProperty(field);
            if (fieldProperty == null)
            {
                return(null);
            }

            var code = fieldProperty.GetValue(generic, null);
#else
            var code = generic is Graphic ? (generic as Graphic).Attributes[field] : null;
#endif
            if (code == null)
            {
                return(null);
            }

            return(code);
        }