public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                string raw = value as string;

                try
                {
                    MeasureDiff mdiff = new MeasureDiff();

                    // Segments
                    string[] parts = raw.Split(new char[] { '(' }, 2);
                    if (parts[0].ToLower()[0] == 'm')
                    {
                        mdiff.MeasureIndex = Int32.Parse(parts[0].Substring(1));
                    }
                    else if (parts[0].ToLower() == "all")
                    {
                        mdiff.MeasureIndex = 0;
                    }
                    else
                    {
                        throw new FormatException("Measure index (e.g. 'm1' or 'all') is missing.");
                    }

                    mdiff.DiffType = (DiffType)Enum.Parse(typeof(DiffType), parts[1].Substring(0, parts[1].Length - 1), true);

                    return(mdiff);
                }
                catch (Exception ex)
                {
                    throw new Exception("Invalid measure diff: " + raw, ex);
                }
            }
        private void GetDiffCalculation(out List <ObjData> dataout, List <ObjData> datain, MeasureDiff[] diff)
        {
            List <ObjData> retdata = new List <ObjData>();

            foreach (ObjData Entity in datain)
            {
                Dictionary <string, ArrayList> EntityValues = new Dictionary <string, ArrayList>();;
                if (Entity.Values.Count > 1)
                {
                    foreach (ObjValue lvalue in Entity.Values)
                    {
                        string    mName = lvalue.FieldName.Substring(0, lvalue.FieldName.IndexOf("."));
                        ArrayList values;
                        if (EntityValues.ContainsKey(mName))
                        {
                            values = EntityValues[mName];
                        }
                        else
                        {
                            values = new ArrayList();
                        }

                        values.Add(lvalue);
                        if (EntityValues.ContainsKey(mName))
                        {
                            EntityValues[mName] = values;
                        }
                        else
                        {
                            EntityValues.Add(mName, values);
                        }
                    }
                    foreach (string key in EntityValues.Keys)
                    {
                        ArrayList values = EntityValues[key];
                        for (int i = 0; i < values.Count - 1; i++)
                        {
                            double   value1, value2;
                            ObjValue objvalue1 = (ObjValue)values[i];
                            ObjValue objvalue2 = (ObjValue)values[i + 1];

                            value1 = Convert.ToDouble(objvalue1.ValueData);
                            value2 = Convert.ToDouble(objvalue2.ValueData);
                            ObjValue    value    = new ObjValue();
                            MeasureDiff mDiff    = GetMeasureDiff(key, diff);
                            DiffType    difftype = mDiff.DiffType;
                            if (mDiff.MeasureIndex > -1)
                            {
                                switch (difftype)
                                {
                                case DiffType.Both:
                                    value.FieldName = key + ".R" + (i + 1).ToString() + ".DiffAbs";
                                    value.ValueData = Convert.ToString(value1 - value2);
                                    Entity.Values.Add(value);
                                    value           = new ObjValue();
                                    value.FieldName = key + ".R" + (i + 1).ToString() + ".DiffRel";
                                    if (value2 != 0)
                                    {
                                        value.ValueData = Convert.ToString(((value1 - value2) / Math.Abs(value2)) * 100);
                                    }
                                    break;

                                case DiffType.DiffAbs:
                                    value.FieldName = key + ".R" + (i + 1).ToString() + ".DiffAbs";
                                    value.ValueData = Convert.ToString(value1 - value2);
                                    break;

                                case DiffType.DiffRel:
                                    value.FieldName = key + ".R" + (i + 1).ToString() + ".DiffRel";
                                    if (value2 != 0)
                                    {
                                        value.ValueData = Convert.ToString(((value1 - value2) / Math.Abs(value2)) * 100);
                                    }
                                    break;
                                }
                            }
                            Entity.Values.Add(value);
                        }
                    }
                    retdata.Add(Entity);
                }
            }
            dataout = retdata;
        }