Jiry_XD
Jiry_XD
Explore posts from servers
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
Some code used a constructor but I made a new class and only wanted to change the class name by the code. Therefore I added the name constructor. To still be able to use object initializers I added the second empty constructor.
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
This worked great. I used implicit operators and ef conversion 😁
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
Hmm I'll look into that, thanks
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
Right, so I want to get the value out of EmailAddress string and store that. (I read about primitive obsession, ... that is why I am trying it this way)
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
Another related question, in EF Core I can do:
[EmailAddress]
[NotMapped]
public EmailAddress? EmailAddress { get; set; }
[EmailAddress]
[NotMapped]
public EmailAddress? EmailAddress { get; set; }
This is in Customer.cs entity. I guess EmailAddress is then not getting stored to the db because it is not mapped. I don't need it mapped I just need to store it as a string. What would be a clean way to do this?
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
Coming from java its a bit getting used to the initializers and auto setters and getters but I am getting the hang of it 😛
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
Thanks 🙂
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
How to prevent nulls using this approach for Object Initializers?
Oh so they can't call the empty constructor witouth a initializer that sets the email?
15 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
Okay thanks 😉 , really appreciate the help
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
What I could do is do a constructor for the test class that does the setup for the tests and then test the setters individually, I think it will look a lot cleaner if you look above the initializer is quite large, what do you think?
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
Thanks for the insights
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
But I still could test them after initialization
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
Thanks
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
damn haha
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
True
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
Oh
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
Most of the properties are required, a typical initializer looks like:
new() {
ShippingAddress=addresses[0],
BillingAddress=addresses[1],
CompanyName="Tech Corp",
ContactPerson="John Doe",
VatNumber="FR0817544902",
EmailAddress=new("[email protected]"),
PhoneNumber="+33 123456789"
},
new() {
ShippingAddress=addresses[0],
BillingAddress=addresses[1],
CompanyName="Tech Corp",
ContactPerson="John Doe",
VatNumber="FR0817544902",
EmailAddress=new("[email protected]"),
PhoneNumber="+33 123456789"
},
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
I think it will become cluttered testing through initializer cause I do have some required props
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
what would you do?
32 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
I am not sure
32 replies