private static IPropertyGetter <TInput, TProperty> GetGetter <TProperty>(string propertyName)
        {
            PropertyInfo property = typeof(TInput).GetProperty(propertyName,
                                                               BindingFlags.Instance | BindingFlags.Public);

            if (property == null || !property.CanRead || !property.HasPublicGetMethod())
            {
                return(null);
            }

            if (property.PropertyType != typeof(TProperty))
            {
                string message = String.Format(CultureInfo.CurrentCulture,
                                               "If the {0} property is present, it must be a {1}.", propertyName, typeof(TProperty).Name);
                throw new InvalidOperationException(message);
            }

            if (property.GetIndexParameters().Length != 0)
            {
                string message = String.Format(CultureInfo.CurrentCulture,
                                               "If the {0} property is present, it must not be an indexer.", propertyName);
                throw new InvalidOperationException(message);
            }

            return(PropertyAccessorFactory <TInput> .CreateGetter <TProperty>(property));
        }
        private static IPropertyGetter <TInput, EntityProperty> GetOtherGetterGeneric <TProperty>(PropertyInfo property)
        {
            IPropertyGetter <TInput, TProperty> propertyGetter =
                PropertyAccessorFactory <TInput> .CreateGetter <TProperty>(property);

            IConverter <TProperty, EntityProperty> converter = TToEntityPropertyConverterFactory.Create <TProperty>();

            return(new ConverterPropertyGetter <TInput, TProperty, EntityProperty>(propertyGetter, converter));
        }
Exemple #3
0
        public void CreateGetter_IfClass_ReturnsInstance()
        {
            // Arrange
            PropertyInfo propertyInfo = typeof(Poco).GetProperty("Value");

            // Act
            IPropertyGetter <Poco, string> manager = PropertyAccessorFactory <Poco> .CreateGetter <string>(propertyInfo);

            // Assert
            Assert.NotNull(manager);
        }