ArcGISPortalViewer.Popup.Primitives.Charting.ChartConverter.Convert C# (CSharp) Метод

Convert() публичный Метод

Modifies the source data before passing it to the target for display in the UI.
public Convert ( object value, Type targetType, object parameter, string language ) : object
value object The source data being passed to the target.
targetType System.Type The of data expected by the target dependency property.
parameter object An optional parameter to be used in the converter logic.
language string
Результат object
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            IDictionary<string, double> pairs = new Dictionary<string, double>();
            if (parameter is String && value is IDictionary<string, object>)
            {
                var attributes = value as IDictionary<string, object>;
                var fields = (parameter as string);
                var normalizeFieldInd = fields.LastIndexOf(BaseChart.NormalizeSeparator);
                double normalizeValue = 0.0;
                if (normalizeFieldInd > 0)
                {
                    var normalizeField = fields.Substring(normalizeFieldInd + BaseChart.NormalizeSeparator.Length);
                    fields = fields.Substring(0, normalizeFieldInd);
                    if (attributes.ContainsKey(normalizeField))
                    {
                        try
                        {
                            normalizeValue = System.Convert.ToDouble(attributes[normalizeField], CultureInfo.InvariantCulture);
                        }
                        catch (Exception)
                        {
                            normalizeValue = 0.0;
                        }
                    }
                }
                foreach (var field in fields.Split(new[] { ',' }))
                {
                    if (attributes.ContainsKey(field))
                    {
                        string label = field;
                        if (KeyToLabelDictionary != null && KeyToLabelDictionary.ContainsKey(field))
                            label = KeyToLabelDictionary[field] as string;

                        double val;
                        try
                        {
                            val = System.Convert.ToDouble(attributes[field], CultureInfo.InvariantCulture);
                        }
                        catch (Exception)
                        {
                            val = 0.0;
                        }
                        if (normalizeValue != 0.0)
                            val /= normalizeValue;
                        pairs.Add(new KeyValuePair<string, double>(label, val));
                    }
                }
            }
            return pairs;
        }