5
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 case of a redundancy here: Codigo = FieldSafer.Safe<int>(dr["someCol"], 0),
where I make mine explicit Safe<int>
, where it could be automatically deleted by Safe(dr...
and the return (defaulValue
) is a whole.
is Correct to suppress redundancy of types? or to facilitate understanding is better to make them explicit?
these methods do what? takes a Datareader and turns it into a Class Type ? if it can answer ?
– user6026
Sorry for the delay, yes, these methods receive the return of the Database and turn into an object
– okevinlira
I have a routine that transfer data coming from the Database read by a datareader is a list, if you want to bring an item also works ... if you think it cool I pass you as answer! @okevinlira
– user6026
Post as Reposta @Fccdias it’s good to have another opinion to evaluate as well. Particularly there are other ways to do this, but I cannot change this structure at my client’s request ;)
– okevinlira