コード例 #1
0
        public void FindValidatorTypeFromReferences()
        {
            var targetType           = typeof(User);
            var validatorGenericType = typeof(IValidator <>).MakeGenericType(new[] { targetType });

            validatorGenericType.IsGenericType.Should().Be.True();

#if !SILVERLIGHT
            var validatorConcreteType =
                AppDomain.CurrentDomain
                .GetAssemblies()
                .SelectMany(asm => asm.GetTypes())
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorGenericType));
#else
            var validatorConcreteType =
                Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .Where(type => RwType.IsSameOrSubclassOrImplementedOf(type, validatorGenericType))
                .FirstOrDefault();
#endif

            validatorConcreteType.Should().Not.Be.Null();

            validatorConcreteType.Should().Be(typeof(UserValidator));
        }
コード例 #2
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));
                    }
                }
            }
        }
コード例 #3
0
        public void FindValidatorType()
        {
            var targetType           = typeof(User);
            var validatorGenericType = typeof(IValidator <>).MakeGenericType(new[] { targetType });

            validatorGenericType.IsGenericType.Should().Be.True();

            var validatorConcreteType =
                Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorGenericType));

            validatorConcreteType.Should().Not.Be.Null();

            validatorConcreteType.Should().Be(typeof(UserValidator));
        }
コード例 #4
0
        /// <summary>
        /// IValidator<T> 형식을 구현한 Validator의 인스턴스를 제공합니다.
        /// </summary>
        /// <param name="validatorType"></param>
        /// <returns></returns>
        public override IValidator CreateInstance(Type validatorType)
        {
            // NOTE: http://docs.castleproject.org/Windsor.Referencing-types-in-XML.ashx

            if (IoC.IsInitialized && IoC.Container.Kernel.HasComponent(validatorType))
            {
                if (IsDebugEnabled)
                {
                    log.Debug("Validator 수형 [{0}] 을 구현한 Concrete Class를 Windsor Container로부터 인스턴싱합니다...", validatorType);
                }

                var result = IoC.Resolve(validatorType);

                if (result != null)
                {
                    return(result as IValidator);
                }
            }

            if (IsDebugEnabled)
            {
                log.Debug("Validator 수형 [{0}] 을 구현한 Concrete Class를 Assembly에서 찾아서 인스턴싱합니다...", validatorType);
            }

            var validatorConcreteType =
                Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorType));

            if (validatorConcreteType != null)
            {
                return(CreateValidatorInstance(validatorConcreteType));
            }

#if !SILVERLIGHT
            validatorConcreteType =
                AppDomain.CurrentDomain
                .GetAssemblies()
                .SelectMany(asm => asm.GetTypes())
                .FirstOrDefault(type => TypeTool.IsSameOrSubclassOrImplementedOf(type, validatorType));
#endif
            return(CreateValidatorInstance(validatorConcreteType));
        }