/// <summary>
        /// Castle.Windsor 환경설정 정보에 있는 속성정보를 Instance의 속성 값으로 매핑한다.
        /// </summary>
        /// <param name="configuration">Castle configuration object</param>
        /// <param name="targetType">target type</param>
        /// <returns></returns>
        public override object PerformConversion(IConfiguration configuration, Type targetType)
        {
            configuration.ShouldNotBeNull("configuration");
            targetType.ShouldNotBeNull("targetType");

            if (IsDebugEnabled)
            {
                log.Debug("Perform conversion configuration value to property. configuration={0}, targetType={1}",
                          configuration, targetType);
            }

            var instance = ActivatorTool.CreateInstance(targetType);

            var accessor = DynamicAccessorFactory.CreateDynamicAccessor(targetType, false);

            const BindingFlags flags = BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            foreach (var itemConfig in configuration.Children)
            {
                var propInfo = targetType.GetProperty(itemConfig.Name, flags);

                // convert from string to object
                var value = Context.Composition.PerformConversion(itemConfig.Value, propInfo.PropertyType);
                accessor.SetPropertyValue(instance, itemConfig.Name, value);
            }
            return(instance);
        }
Beispiel #2
0
        protected virtual void DoSetupCommand(DbCommand cmd)
        {
            //  NOTE: Oracle 인 경우 다음과 같은 코드가 추가되어야 한다.

            var accessor = DynamicAccessorFactory.CreateDynamicAccessor <DbCommand>(MapPropertyOptions.Safety);

            accessor.SetPropertyValue(cmd, "BindByName", true);
        }
Beispiel #3
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));
        }
Beispiel #4
0
        /// <summary>
        /// Gets the current value of the property on a component
        /// </summary>
        /// <param name="component">The component with the property for which to retrieve the value.</param>
        /// <returns>The value of a property for a given component.</returns>
        public override object GetValue(object component)
        {
            object instance = GetNestedObjectInstance(component, _propertyPath, false);

            if (instance != null)
            {
                return(DynamicAccessorFactory.GetDynamicAccessor(instance.GetType()).GetPropertyValue(instance, _originalPropertyDescriptor.Name));
            }
            else
            {
                return(null);
            }
        }
        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));
                    }
                }
            }
        }
        public void GenerateXmlByDynamicAccessor()
        {
            var accessor2 = DynamicAccessorFactory.CreateDynamicAccessor(typeof(CosmeticAttribute), false);

            var cosmetic = new CosmeticAttribute
            {
                BgSWF = "~/FusionCharts/BgChart.swf"
            };

            var sb = new StringBuilder();

            using (var writer = new XmlTextWriter(new StringWriter(sb))) {
                writer.WriteStartDocument(true);
                writer.WriteStartElement("chart");

                GenerateXmlAttributes(writer, accessor2, cosmetic);

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

            Console.WriteLine(sb.ToString());
        }
Beispiel #7
0
 /// <summary>
 /// 지정된 수형의 속성, 필드를 동적으로 접근할 수 있도록 해주는 <see cref="IDynamicAccessor"/>를 생성합니다.
 /// </summary>
 /// <param name="type">대상 수형</param>
 /// <param name="mapOptions">매핑 옵션</param>
 internal static IDynamicAccessor GetDynamicAccessor(Type type, MapPropertyOptions mapOptions = null)
 {
     return(DynamicAccessorFactory.CreateDynamicAccessor(type, mapOptions ?? MapPropertyOptions.Safety));
 }
Beispiel #8
0
 /// <summary>
 /// 수형 {T} 의 인스턴스의 속성 및 필드에 동적으로 접근할 수 있도록 해주는 <see cref="IDynamicAccessor{T}"/>를 생성합니다.
 /// </summary>
 /// <typeparam name="T">대상 수형</typeparam>
 /// <param name="mapOptions">매핑 옵션</param>
 /// <seealso cref="TypeConvertableDynamicAccessor{T}"/>
 internal static IDynamicAccessor <T> GetDynamicAccessor <T>(MapPropertyOptions mapOptions = null)
 {
     return(DynamicAccessorFactory.CreateDynamicAccessor <T>(mapOptions ?? MapPropertyOptions.Safety));
 }
Beispiel #9
0
            public static ResultRow ToResultRow(ResultEntity resultEntity)
            {
                var accessor = DynamicAccessorFactory.CreateDynamicAccessor <ResultEntity>();

                return(new ResultRow(accessor.GetPropertyNameValueCollection(resultEntity).ToDictionary(p => p.Key, p => p.Value)));
            }