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?
In C# I have this class:
using System.Diagnostics.CodeAnalysis;
using System.Net.Mail;

namespace Domain.Customers;

public class EmailAddress
{
private MailAddress email;

public EmailAddress()
{
// Default constructor so I can use object initializer.
}

[SetsRequiredMembers]
public EmailAddress(string email)
{
Email = email;
}
public required string Email
{
get => email.ToString();
set => email = new MailAddress(value);
}

}
using System.Diagnostics.CodeAnalysis;
using System.Net.Mail;

namespace Domain.Customers;

public class EmailAddress
{
private MailAddress email;

public EmailAddress()
{
// Default constructor so I can use object initializer.
}

[SetsRequiredMembers]
public EmailAddress(string email)
{
Email = email;
}
public required string Email
{
get => email.ToString();
set => email = new MailAddress(value);
}

}
As you can see I have two constructors, when using object initializers I need to use one of them. I like using object initializers using no constructor aka the default constructor but because I added it there is no default so I added it. But now the problem is that people can call new EmailAddress() without passing an email and it can stay null that way? How can I still be able to have an empty constructor so I can use object initializers without having the risk somoene calls new EmailAdress();?
13 replies
CC#
Created by Jiry_XD on 10/21/2024 in #help
Test setters indirectly via constructor or test them directly?
Title 🙂
32 replies
CC#
Created by Jiry_XD on 9/30/2024 in #help
✅ What's new in .NET 8 regarding making a WASM project?
Hello guys, I am looking into learning Blazor WASM. I was viewing some tutorials online on how to setup the project but everything seems to have changed since .NET 8. Normally you could make a Blazor WASM project + ASP .NET Core hosted, now you have to do it manually? Or is there still an option to do it automatically? Why did they remove it, is it not the standard anymore? If so what is the new standard?
46 replies