Is your feature request related to a problem? Please describe.
The .Default() mapping includes a useOnConversionFailure parameter, which sets the default value for a field on conversion failure.
The attribute for Default does not know about this parameter.
Unfortunately, the .Default() is broken, too, as I described in #2156.
Describe the solution you'd like
Extend the DefaultAttribute to include the useOnConversionFailure parameter, like so:
[Default(null, UseOnConversionFailure = true)]
public Guid? Id { get; set; }
Describe alternatives you've considered
Only use the .Default() method for the fields.
However, this is really tedious for declarative models, since I don't use any custom mappings aside from this one.
Also, this means that the .Default() API and the attribute API will differ slightly, so there's no feature parity.
Additional context
I have a generic type with a generic property, called Twin. Instead of specifying the attributes directly in the necessary model, I need to follow antipatterns (or duplicate class map code) in order to cover all possible types passed to the generic (note the typeof check):
public class TwinImportRequestMap<TTwin> : ClassMap<TwinImportRequest<TTwin>>
where TTwin : TwinImportData
{
public TwinImportRequestMap(IEnumerable<string> schemaKeys)
{
this.References<TwinImportDataMap<TTwin>>(m => m.Twin);
this.Map(m => m.Properties).Name(schemaKeys.ToArray());
}
public class TwinImportDataMap<TTwinImportData> : ClassMap<TTwinImportData>
where TTwinImportData : TwinImportData
{
public TwinImportDataMap()
{
this.AutoMap(CultureInfo.InvariantCulture);
this.Map(x => x.Id)
.TypeConverter<NullableGuidConverter>()
.Default((Guid?) null, useOnConversionFailure: true);
if (typeof(TTwin) == typeof(AssetImportData))
{
(this as TwinImportDataMap<AssetImportData>)
.Map(x => x.LocatedIn)
.TypeConverter<NullableGuidConverter>()
.Default((Guid?) null, useOnConversionFailure: true);
}
}
}
}
Is your feature request related to a problem? Please describe. The
.Default()
mapping includes auseOnConversionFailure
parameter, which sets the default value for a field on conversion failure. The attribute forDefault
does not know about this parameter. Unfortunately, the.Default()
is broken, too, as I described in #2156.Describe the solution you'd like Extend the
DefaultAttribute
to include theuseOnConversionFailure
parameter, like so:This will result in a cleaner solution for the client. Instead of:
we will use:
Describe alternatives you've considered Only use the
.Default()
method for the fields. However, this is really tedious for declarative models, since I don't use any custom mappings aside from this one. Also, this means that the.Default()
API and the attribute API will differ slightly, so there's no feature parity.Additional context I have a generic type with a generic property, called
Twin
. Instead of specifying the attributes directly in the necessary model, I need to follow antipatterns (or duplicate class map code) in order to cover all possible types passed to the generic (note thetypeof
check):