/// <summary>
        /// Ignores a property for comparison result purposes.  A property can be included in the
        /// comparison process, can be ignored when compared against objects of the same type, can
        /// be ignored when compared against objects of a different type, or it can be ignored for
        /// all comparisons.
        /// </summary>
        /// <typeparam name="TProperty">The property's return type.</typeparam>
        /// <param name="propertyExpr">Property lambda expression.</param>
        /// <param name="ignoreOption">The desired ignore option.</param>
        /// <returns>This type configuration object to enable fluent syntax.</returns>
        public TypeConfiguration <TSource> IgnoreProperty <TProperty>(
            Expression <Func <TSource, TProperty> > propertyExpr,
            IgnorePropertyOptions ignoreOption
            )
        {
            PropertyInfo pInfo = ExpressionHelper.GetPropertyInfo(propertyExpr, nameof(propertyExpr));

            lock (Scanner.SyncRoot)
            {
                TypeInfo.Properties[pInfo.Name].IgnoreProperty = ignoreOption;
            }
            return(this);
        }
Beispiel #2
0
        public void TypeConfigurationCanSetPropertyToIgnore()
        {
            //Arrange.
            var config = Scanner.ConfigureType <Person>();

            Scanner.TryGetTypeInformation(typeof(Person), out TypeInfo ti);
            IgnorePropertyOptions beforeIgnore = ti.Properties[nameof(Person.Email)].IgnoreProperty;

            //Act.
            config.IgnoreProperty(src => src.Email, IgnorePropertyOptions.IgnoreForAll);

            //Assert.
            beforeIgnore.Should().Be(IgnorePropertyOptions.DoNotIgnore);
            ti.Properties[nameof(Person.Email)].IgnoreProperty.Should().Be(IgnorePropertyOptions.IgnoreForAll);
        }
 /// <summary>
 /// Creates a new instance of this class.
 /// </summary>
 public IgnoreForComparisonAttribute(IgnorePropertyOptions ignoreOptions = IgnorePropertyOptions.IgnoreForOthers)
     : base()
 {
     IgnoreOptions = ignoreOptions;
 }
 /// <summary>
 /// Creates a new instance of this class.
 /// </summary>
 /// <param name="propertyDescriptor">Original roperty descriptor object.</param>
 /// <param name="ignoreProperty">A Boolean value that determines if the property is
 /// ignored for comparison against any target data type without a property map.</param>
 public PropertyComparisonInfo(PropertyDescriptor propertyDescriptor, IgnorePropertyOptions ignoreProperty)
 {
     PropertyDescriptor = propertyDescriptor ?? throw new ArgumentNullException(nameof(propertyDescriptor));
     IgnoreProperty     = ignoreProperty;
 }