Ejemplo n.º 1
0
        private static IPropertySetter <TOutput, TProperty> GetSetter <TProperty>(string propertyName)
        {
            PropertyInfo property = typeof(TOutput).GetProperty(propertyName,
                                                                BindingFlags.Instance | BindingFlags.Public);

            if (property == null || !property.CanWrite || !property.HasPublicSetMethod())
            {
                return(null);
            }

            if (property.PropertyType != typeof(TProperty))
            {
                string message = String.Format(CultureInfo.InvariantCulture,
                                               "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.InvariantCulture,
                                               "If the {0} property is present, it must not be an indexer.", propertyName);
                throw new InvalidOperationException(message);
            }

            return(PropertyAccessorFactory <TOutput> .CreateSetter <TProperty>(property));
        }
Ejemplo n.º 2
0
        private static IPropertySetter <TOutput, EntityProperty> GetOtherSetterGeneric <TProperty>(PropertyInfo property)
        {
            IConverter <EntityProperty, TProperty> converter      = EntityPropertyToTConverterFactory.Create <TProperty>();
            IPropertySetter <TOutput, TProperty>   propertySetter =
                PropertyAccessorFactory <TOutput> .CreateSetter <TProperty>(property);

            return(new ConverterPropertySetter <TOutput, TProperty, EntityProperty>(converter, propertySetter));
        }
Ejemplo n.º 3
0
        public void CreateSetter_IfClass_ReturnsInstance()
        {
            // Arrange
            PropertyInfo propertyInfo = typeof(Poco).GetProperty("Value");

            // Act
            IPropertySetter <Poco, string> manager = PropertyAccessorFactory <Poco> .CreateSetter <string>(propertyInfo);

            // Assert
            Assert.NotNull(manager);
        }