Beispiel #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 (!Chart.ActualCategoryValues.Contains(value.ToString()))
                    {
                        Chart.ActualCategoryValues.Add(value.ToString());
                    }
                    return(Chart.ActualCategoryValues.IndexOf(value.ToString()));
                }
                else
                {
                    throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));
                }
            }
            return(0d);
        }
Beispiel #2
0
        static bool DecimalValidation(FastProperty propertie, DecimalRuleAttribute attr, StringBuilder strBuilder)
        {
            string Name  = propertie.PropertyName;
            object Value = propertie.Get();

            if (attr.Greater.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) > Convert.ToDecimal(attr.Greater))
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能大于{attr.Greater}"));
                return(false);
            }
            if (attr.Less.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) < Convert.ToDecimal(attr.Less))
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能小于{attr.Less}"));
                return(false);
            }
            if (attr.Equal.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) == Convert.ToDecimal(attr.Equal))
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能等于{attr.Equal}"));
                return(false);
            }
            if (attr.NoEqual.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) != Convert.ToDecimal(attr.NoEqual))
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"必须等于{attr.NoEqual}"));
                return(false);
            }
            if (attr.Precision.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value).GetPrecision() > (int?)attr.Precision)
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"精度不能超过{attr.Precision}"));
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public void Close()
        {
            foreach (var category in _counterCache.Values)
            {
                // for each property dispose of the instance counters
                foreach (var propertyInfo in category.GetType().GetProperties())
                {
                    var fp = new FastProperty(propertyInfo);
                    ((Counter)fp.Get(category)).Dispose();
                }
            }

            _counterCache.Clear();
        }
Beispiel #4
0
        public PropertyNode(int id, PropertyInfo propertyInfo)
            : base(id)
        {
            _property = propertyInfo;

            var fastProperty = new FastProperty <T, TProperty>(propertyInfo);

            _propertyMatch = (x, next) =>
            {
                if (x != null)
                {
                    next(fastProperty.Get(x));
                }
            };
        }
Beispiel #5
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();
                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 (!Chart.ActualCategoryValues.Contains(value.ToString()))
                            {
                                Chart.ActualCategoryValues.Add(value.ToString());
                            }
                            return(Chart.ActualCategoryValues.IndexOf(value.ToString()));
                        }
                        else
                        {
                            throw new NotSupportedException(String.Format("The {0} type is Not Supported by Chart", path));
                        }
                    }
                }
            }
            return(0d);
        }
Beispiel #6
0
        public void Should_be_able_to_access_a_private_setter()
        {
            PrivateSetter instance = new PrivateSetter();

            var property = instance.GetType()
                           .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                           .Where(x => x.Name == "Name")
                           .First();


            var fastProperty = new FastProperty <PrivateSetter>(property, BindingFlags.NonPublic);

            const string expectedValue = "Chris";

            fastProperty.Set(instance, expectedValue);

            Assert.AreEqual(expectedValue, fastProperty.Get(instance));
        }
Beispiel #7
0
        static bool StringValidation(FastProperty propertie, StringRuleAttribute attr, StringBuilder strBuilder)
        {
            string Name  = propertie.PropertyName;
            object Value = propertie.Get();

            if (attr.MinLength.NotNull() && Value.NotNull() && Value.ToString().Length < (int?)attr.MinLength)
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能少于{attr.MinLength}位"));
                return(false);
            }
            if (attr.MaxLength.NotNull() && Value.NotNull() && Value.ToString().Length > (int?)attr.MaxLength)
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能超过{attr.MaxLength}位"));
                return(false);
            }
            if (attr.RegExp.NotNull() && Value.NotNull() && !Regex.IsMatch(Value.ToString(), attr.RegExp))
            {
                strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"正则匹配失败"));
                return(false);
            }
            return(true);
        }
        public void ApplyTo(Configuration cfg, UntypedChannel channel)
        {
            if (_types.Count == 0)
            {
                return;
            }

            PropertyInfo propertyInfo = _listenerAccessor.GetMemberPropertyInfo();
            var          property     = new FastProperty <EventListeners, TListener[]>(propertyInfo);

            TListener listener = _listenerFactory(channel, _types);

            TListener[] existing = property.Get(cfg.EventListeners);
            if (existing == null || existing.Length == 0)
            {
                property.Set(cfg.EventListeners, new[] { listener });
            }
            else
            {
                property.Set(cfg.EventListeners, existing.Concat(Enumerable.Repeat(listener, 1)).ToArray());
            }
        }
Beispiel #9
0
        private void BindEventAction(int all, int i, FastProperty <T, int> property)
        {
            var e      = _sources[i];
            var eevent = BasicEvent <T> .GetEvent(e);

            var eventAction = new BasicEventAction <T>(eevent);

            int flag = 1 << i;

            eventAction.Then(x =>
            {
                int value = property.Get(x) | flag;
                property.Set(x, value);

                if (value == all)
                {
                    x.RaiseEvent(_target);
                }
            });

            _bindEventAction(eventAction);
        }
Beispiel #10
0
 static bool BasicValidation <T>(FastProperty propertie, T attr, StringBuilder strBuilder) where T : BasicAttribute
 {
     if (attr.NotNull() && attr.Message.NotNull())
     {
         Type   Type  = propertie.PropertyType;
         string Name  = propertie.PropertyName;
         object Value = propertie.Get();
         if (attr.Required == true && Value.IsNull())
         {
             strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", "必须赋值"));
             return(false);
         }
         if (attr is StringRuleAttribute)
         {
             if (!StringValidation(propertie, attr as StringRuleAttribute, strBuilder))
             {
                 return(false);
             }
         }
         if (attr is NumericRuleAttribute)
         {
             if (!NumericValidation(propertie, attr as NumericRuleAttribute, strBuilder))
             {
                 return(false);
             }
         }
         if (attr is DecimalRuleAttribute)
         {
             if (!DecimalValidation(propertie, attr as DecimalRuleAttribute, strBuilder))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #11
0
 public State <TInstance> Get(TInstance instance)
 {
     return(_property.Get(instance) as State <TInstance> ?? _defaultState);
 }
Beispiel #12
0
 public void GetText(int index)
 {
     string value = _textProperty.Get(Objects[index % ObjectCount]);
 }
Beispiel #13
0
 public void GetValue(int index)
 {
     int value = _valueProperty.Get(Objects[index % ObjectCount]);
 }
Beispiel #14
0
        /// <summary>
        /// Call the accessor method
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>

        public override Object GetValue(object component)
        {
            return(propInfo.Get(component));
        }
Beispiel #15
0
 public string Magnum_CompiledExpressionTrees()
 {
     return((string)fastProperty.Get(testUri));
 }