Visual Studio 2017 suggested something that surprised me, creating an object without using the new operator, I was surprised because I'm coming from Java and it's been a year since I was stopped and I decided to go back to school.
Well, when creating a new Enterprise object, it does not appear the fields of the Address class that are declared inside the Company class, but inside it also has the class Plan and this Yes, they appear to complete.
I can not see wrong, because the two classes are almost equal, taking away the fact that Plan receives inheritance of the class Persistant.
Below is the code to see the classes:
Business Class
namespace Cobranca.pkgModel
{
public class Empresa : Persistant
{
private string nome;
private string razaoSocial;
private string cnpj;
private string status;
private Plano plano;
private Endereco endereco;
public Empresa()
{
Endereco = new Endereco();
Plano = new Plano();
}
//métodos getter e setter
}
}
Plan Class
namespace Cobranca.pkgModel
{
public class Plano : Persistant
{
private string nome;
private string tipoCobranca;
private double valor;
//métodos getter e setter
}
}
Class Address
namespace Cobranca.pkgModel
{
public class Endereco
{
private string logradouro;
private string numero;
private string bairro;
private string complemento;
private string cep;
private string cidade;
private string estado;
//métodos getter e setter
}
}
Below is the print I took from the screen
SomeoneknowstoanswermebecauseI'mgoingthroughthis,beingthatIcreatedanequalmethodinclassPlanoDAO
anddoesnotshowthisfault.
Andwhatisthenameofthisfunctionalityformetostudy,doesthishavetobewithlambda
?
Thankyou
Answer:
JusttonoteIeditedmycodeastheconfreresreporteditanditlookedlikethis:
this.Model=newEmpresa{Id=Convert.ToInt32(data["id"]),
Nome = Convert.ToString(data["nome"]),
RazaoSocial = Convert.ToString(data["razao_social"]),
Cnpj = Convert.ToString(data["cnpj"]),
Status = Convert.ToString(data["status"]),
};
this.Model.Plano = new Plano
{
Id = Convert.ToInt32(data["plano_pk"]),
Nome = Convert.ToString(data["plano_nome"]),
Valor = Convert.ToDouble(data["plano_valor"])
};
this.Model.Endereco = new Endereco
{
Logradouro = Convert.ToString(data["logradouro"]),
Numero = Convert.ToString(data["numero"]),
Bairro = Convert.ToString(data["bairro"]),
Complemento = Convert.ToString(data["complemento"]),
Cep = Convert.ToString(data["cep"]),
Cidade = Convert.ToString(data["cidade"]),
Estado = Convert.ToString(data["estado"])
};