コード例 #1
0
        /// <summary>
        /// 요소의 속성 값을 인덱싱합니다.
        /// </summary>
        private static void AddToIndex(T item, string propertyName, MultiMap <int, T> index)
        {
            if (Equals(item, null))
            {
                return;
            }

            object propertyValue = Accessor.GetPropertyValue(item, propertyName);

            if (IsDebugEnabled)
            {
                log.Debug("해당 요소[{0}] 의 속성 [{1}] 의 값은 [{2}] 입니다.", item, propertyName, propertyValue);
            }

            if (propertyValue != null)
            {
                var hash = propertyValue.GetHashCode();
                if (index.ContainsKey(hash))
                {
                    index[hash].Add(item);
                }
                else
                {
                    //List<T> newList = new List<T> {item};
                    //index.Add(hash, newList);
                    index.Add(hash, item);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// 객체의 모든 속성에 대해 속성명-속성값 형식을 반환합니다.
 /// </summary>
 /// <typeparam name="T">대상 객체의 수형</typeparam>
 /// <param name="accessor">IDynamicAccessor{T} 인스턴스</param>
 /// <param name="target">대상 객체</param>
 /// <returns></returns>
 public static IEnumerable <KeyValuePair <string, object> > GetPropertyNameValueCollection <T>(this IDynamicAccessor <T> accessor,
                                                                                               T target)
 {
     return
         (accessor.GetPropertyNames()
          .Select(name => new KeyValuePair <string, object>(name, accessor.GetPropertyValue(target, name))));
 }
コード例 #3
0
        private static object GetNestedObjectInstance(object component, string propertyPath, bool autoCreate)
        {
            string propertyName;

            if (propertyPath.Contains("."))
            {
                propertyName = propertyPath.Substring(0, propertyPath.IndexOf("."));
            }
            else
            {
                return(component);
            }

            IDynamicAccessor dynamicAccessor = DynamicAccessorFactory.GetDynamicAccessor(component.GetType());
            object           value           = dynamicAccessor.GetPropertyValue(component, propertyName);

            if (value == null)
            {
                if (autoCreate)
                {
                    PropertyDescriptor descriptor = ReflectionHelper.GetPropertyDescriptorFromPath(component.GetType(), propertyName);
                    value = Activator.CreateInstance(descriptor.PropertyType);
                    dynamicAccessor.SetPropertyValue(component, propertyName, value);
                }
                else
                {
                    return(value);
                }
            }
            return(GetNestedObjectInstance(value, propertyPath.Substring(propertyPath.IndexOf(".") + 1), autoCreate));
        }
コード例 #4
0
        /// <summary>
        /// Determines whether the specified instance is valid.
        /// </summary>
        /// <param name="instance">The instance declaring the property to be validated</param>
        /// <returns>
        ///     <c>true</c> if the specified instance is valid; otherwise, <c>false</c>.
        /// </returns>
        public bool IsValid(object instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            IDynamicAccessor DynamicAccessor = DynamicAccessorFactory.GetDynamicAccessor(instance.GetType());

            object value = DynamicAccessor.GetPropertyValue(instance, _propertyName);

            return(Validate(value));
        }
コード例 #5
0
        private static void GenerateXmlAttributes <T>(XmlWriter writer, IDynamicAccessor accessor, T instance) where T : IChartObject
        {
            foreach (var propertyName in accessor.GetPropertyNames())
            {
                var propertyValue = accessor.GetPropertyValue(instance, propertyName);
                if (propertyValue != null)
                {
                    Type propertyType = accessor.GetPropertyType(propertyName);

                    if (propertyType.IsSimpleType() || propertyType.IsValueType)
                    {
                        if (IsDebugEnabled)
                        {
                            log.Debug("Property name={0}, type={1}, value={2}", propertyName, propertyType, propertyValue);
                        }

                        // NOTE : Color인 경우는 HexString으로, Enum 값은 HashCode 값으로...
                        if (propertyType == typeof(Color?))
                        {
                            var color = (Color?)propertyValue;
                            writer.WriteAttributeString(propertyName, color.Value.ToHexString());
                        }
                        else if (propertyType.IsEnum)
                        {
                            writer.WriteAttributeString(propertyName, propertyValue.GetHashCode().ToString());
                        }
                        else
                        {
                            writer.WriteAttributeString(propertyName, propertyValue.ToString());
                        }
                    }
                    else if (propertyType.IsSameOrSubclassOf(typeof(ChartAttributeBase)))
                    {
                        var accessor2 = DynamicAccessorFactory.CreateDynamicAccessor(propertyType, false);
                        GenerateXmlAttributes(writer, accessor2, propertyValue as ChartAttributeBase);
                    }
                    else if (TypeTool.IsSameOrSubclassOrImplementedOf(propertyType, typeof(IEnumerable)))
                    {
                        // Nothing to do.
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("지원하지 않는 속성입니다.  property name={0}, type={1}", propertyName,
                                                                      propertyType.FullName));
                    }
                }
            }
        }