Let\'s say I have the following \"destination\" class:
public class Destination
{
public String WritableProperty { get; set; }
pu
Write Extension Method as shown below:
public static class IgnoreReadOnlyExtensions
{
public static IMappingExpression IgnoreReadOnly(
this IMappingExpression expression)
{
var sourceType = typeof(TSource);
foreach (var property in sourceType.GetProperties())
{
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(sourceType)[property.Name];
ReadOnlyAttribute attribute = (ReadOnlyAttribute) descriptor.Attributes[typeof(ReadOnlyAttribute)];
if(attribute.IsReadOnly == true)
expression.ForMember(property.Name, opt => opt.Ignore());
}
return expression;
}
}
To call extension method:
Mapper.CreateMap