Given the following code:
public override Entidades.ControleAcesso.Perfil PreencherEntidade(IDataReader dr)
{
return new Entidades.ControleAcesso.Perfil()
{
Codigo = FieldSafer.Safe<int>(dr["someCol"], 0),
Nome = FieldSafer.Safe<string>(dr["someCol"], "nothing"),
PerfilFuncionalidade = new List<PerfilFuncionalidade>(),
StatusRegistro = FieldSafer.Safe<StatusRegistroEnum>(dr["someCol"], StatusRegistroEnum.Ativo),
};
}
Where FieldSafer =
public class FieldSafer : MinhaClasseBase
{
private T ObjectSafe<T>(object field, T defaultValue)
{
return GetSafeField<T>(field, defaultValue);
}
public static T Safe<T>(object field, T defaultValue)
{
return new FieldSafer().ObjectSafe<T>(field, defaultValue);
}
}
I suffer in the case of redundancy here: Codigo = FieldSafer.Safe<int>(dr["someCol"], 0),
where I leave explicit my Safe<int>
, where it could be automatically suppressed by Safe(dr...
and the return ( defaulValue
) is an integer.
Is it OK to suppress type redundancy? or to facilitate understanding, is it best to make them explicit?