Esempio n. 1
0
        /// <summary>
        /// Gets the reflection value from item.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        /// <exception cref="System.NotSupportedException"></exception>
        public double GetReflectionValueFromItem(string path, Object item)
        {
#if !WINRT
            PropertyInfo propertInfo = item.GetType().GetProperty(path);
#else
            PropertyInfo propertInfo = item.GetType().GetRuntimeProperty(path);
#endif
            FastProperty fastPropertInfo = new FastProperty(propertInfo);

            if (propertInfo != null)
            {
                object value = fastPropertInfo.Get(item);
                if (value is Double || value is int)
                {
                    return(Double.Parse(value.ToString()));
                }
                else if (value is DateTime)
                {
                    return(((DateTime)value).ToOADate());
                }
                else if (value is String)
                {
                    if (!SparrowChart.ActualCategoryValues.Contains(value.ToString()))
                    {
                        SparrowChart.ActualCategoryValues.Add(value.ToString());
                    }
                    return(SparrowChart.ActualCategoryValues.IndexOf(value.ToString()));
                }
                else
                {
                    throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));
                }
            }
            return(0d);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the reflection value.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="source">The source.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        /// <exception cref="System.NotSupportedException"></exception>
        public double GetReflectionValue(string path, IEnumerable source, int position)
        {
            if (!String.IsNullOrEmpty(path))
            {
                IEnumerator enumerator = source.GetEnumerator();
                double      index      = 0;
                for (int i = 0; i < position - 1; i++)
                {
                    enumerator.MoveNext();
                }

                if (enumerator.MoveNext())
                {
#if !WINRT
                    PropertyInfo propertInfo = enumerator.Current.GetType().GetProperty(path);
#else
                    PropertyInfo propertInfo = enumerator.Current.GetType().GetRuntimeProperty(path);
#endif
                    FastProperty fastPropertInfo = new FastProperty(propertInfo);
                    if (propertInfo != null)
                    {
                        object value = fastPropertInfo.Get(enumerator.Current);
                        if (value is Double || value is int)
                        {
                            return(Double.Parse(value.ToString()));
                        }
                        else if (value is DateTime)
                        {
                            return(((DateTime)value).ToOADate());
                        }
                        else if (value is String)
                        {
                            if (!SparrowChart.ActualCategoryValues.Contains(value.ToString()))
                            {
                                SparrowChart.ActualCategoryValues.Add(value.ToString());
                            }
                            return(SparrowChart.ActualCategoryValues.IndexOf(value.ToString()));
                        }
                        else
                        {
                            throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));
                        }
                    }
                }
            }
            return(0d);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the reflection values.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="source">The source.</param>
        /// <param name="oldValues">The old values.</param>
        /// <param name="isUpdate">if set to <c>true</c> [is update].</param>
        /// <returns></returns>
        /// <exception cref="System.NotSupportedException"></exception>
        public List <double> GetReflectionValues(string path, IEnumerable source, List <double> oldValues, bool isUpdate)
        {
            List <double> values;

            if (isUpdate)
            {
                values = oldValues;
            }
            else
            {
                values = new List <double>();
            }
            bool notifyCollectionChanged = false;

            if (!string.IsNullOrEmpty(path) && (source != null))
            {
                IEnumerator enumerator = source.GetEnumerator();
                double      index      = 0d;

                if (enumerator.MoveNext())
                {
                    if (enumerator.Current is INotifyPropertyChanged)
                    {
                        notifyCollectionChanged = true;
                    }
#if !WINRT
                    PropertyInfo xPropertInfo = enumerator.Current.GetType().GetProperty(path);
#else
                    PropertyInfo xPropertInfo = enumerator.Current.GetType().GetRuntimeProperty(path);
#endif
                    FastProperty fastPropertInfo = new FastProperty(xPropertInfo);
                    do
                    {
                        if (xPropertInfo != null)
                        {
                            object value = fastPropertInfo.Get(enumerator.Current);
                            if (value is Double || value is int)
                            {
                                values.Add(Double.Parse(value.ToString()));
                            }
                            else if (value is DateTime)
                            {
                                values.Add(((DateTime)value).ToOADate());
                            }
                            else if (value is String)
                            {
                                if (!SparrowChart.ActualCategoryValues.Contains(value.ToString()))
                                {
                                    SparrowChart.ActualCategoryValues.Add(value.ToString());
                                }
                                values.Add(SparrowChart.ActualCategoryValues.IndexOf(value.ToString()));
                            }
                            else
                            {
                                throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));
                            }
                            index++;
                        }
                    } while (enumerator.MoveNext());
                    if (notifyCollectionChanged)
                    {
                        enumerator.Reset();
                        while (enumerator.MoveNext())
                        {
                            (enumerator.Current as INotifyPropertyChanged).PropertyChanged -= Collection_PropertyChanged;
                            (enumerator.Current as INotifyPropertyChanged).PropertyChanged += Collection_PropertyChanged;
                        }
                    }
                }
            }
            return(values);
        }
Esempio n. 4
0
        public List<double> GetReflectionValues(string path,IEnumerable source, List<double> oldValues,bool isUpdate)
        {
            List<double> values;
            if(isUpdate)
                values=oldValues;
            else
                values = new List<double>();
            bool notifyCollectionChanged=false;
            if (!string.IsNullOrEmpty(path))
            {
                IEnumerator enumerator = source.GetEnumerator();
                double index = 0d;

                if (enumerator.MoveNext())
                {
                    if (enumerator.Current is INotifyPropertyChanged)
                        notifyCollectionChanged = true;
                    PropertyInfo xPropertInfo = enumerator.Current.GetType().GetProperty(path);

                    FastProperty fastPropertInfo = new FastProperty(xPropertInfo);
                    do
                    {
                        if (xPropertInfo != null)
                        {
                            object value = fastPropertInfo.Get(enumerator.Current);
                            if (value is Double || value is int)
                            {
                                values.Add(Double.Parse(value.ToString()));
                            }
                            else if (value is DateTime)
                            {
                                values.Add(((DateTime)value).ToOADate());
                            }
                            else if (value is String)
                            {
                                if (!SparrowChart.ActualCategoryValues.Contains(value.ToString()))
                                    SparrowChart.ActualCategoryValues.Add(value.ToString());
                                values.Add(SparrowChart.ActualCategoryValues.IndexOf(value.ToString()));
                            }
                            else
                                throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));
                            index++;
                        }
                    } while (enumerator.MoveNext());
                    if (notifyCollectionChanged)
                    {
                        enumerator.Reset();
                        while (enumerator.MoveNext())
                        {
                            (enumerator.Current as INotifyPropertyChanged).PropertyChanged -= Collection_PropertyChanged;
                            (enumerator.Current as INotifyPropertyChanged).PropertyChanged += Collection_PropertyChanged;
                        }

                    }
                }

            }
            return values;
        }
Esempio n. 5
0
        public double GetReflectionValueFromItem(string path, Object item)
        {
            PropertyInfo propertInfo = item.GetType().GetProperty(path);
            FastProperty fastPropertInfo = new FastProperty(propertInfo);

            if (propertInfo != null)
            {
                object value = fastPropertInfo.Get(item);
                if (value is Double || value is int)
                {
                    return Double.Parse(value.ToString());
                }
                else if (value is DateTime)
                {
                    return ((DateTime)value).ToOADate();
                }
                else if (value is String)
                {
                    if (!SparrowChart.ActualCategoryValues.Contains(value.ToString()))
                        SparrowChart.ActualCategoryValues.Add(value.ToString());
                    return SparrowChart.ActualCategoryValues.IndexOf(value.ToString());
                }
                else
                    throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));
            }
            return 0d;
        }
Esempio n. 6
0
        public double GetReflectionValue(string path, IEnumerable source, int position)
        {
            if (!String.IsNullOrEmpty(path))
            {
                IEnumerator enumerator = source.GetEnumerator();
                double index = 0;
                for (int i = 0; i < position - 1; i++)
                {
                    enumerator.MoveNext();
                }

                if (enumerator.MoveNext())
                {
                    PropertyInfo propertInfo = enumerator.Current.GetType().GetProperty(path);
                    FastProperty fastPropertInfo = new FastProperty(propertInfo);
                    if (propertInfo != null)
                    {
                        object value = fastPropertInfo.Get(enumerator.Current);
                        if (value is Double || value is int)
                        {
                            return Double.Parse(value.ToString());
                        }
                        else if (value is DateTime)
                        {
                            return ((DateTime)value).ToOADate();
                        }
                        else if (value is String)
                        {
                            if (!SparrowChart.ActualCategoryValues.Contains(value.ToString()))
                                SparrowChart.ActualCategoryValues.Add(value.ToString());
                            return SparrowChart.ActualCategoryValues.IndexOf(value.ToString());
                        }
                        else
                            throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));

                    }
                }
            }
            return 0d;
        }