Proposal: custom constructors handling
See original GitHub issueI think it’s a good idea to implement custom constructor support (and analysis). For example, I want the following behavior to work as expected:
[InitRequired]
public class Address
{
// Default constructor should NOT report CS8618 (since we are using InitRequired).
public Address() { }
// This constructor SHOULD report CS8618 (since it doesn't set all non-nullable fields).
// Even though we have InitRequired attribute set.
public Address(string city)
{
City = city;
}
// This constructor should NOT report CS8618 (since it initializes the object in a valid state).
public Address(string city, bool hasStreet)
{
City = city;
Street = hasStreet ? "Default avenue" : "Unknown";
}
public string City { get; set; }
public string Street { get; set; }
public string? SecondAddress { get; set; }
}
static class Program
{
static void Main()
{
// CSE001: Missing initialization of all 3 fields.
var message = new Address();
// CSE001: Missing initialization of 2 fields.
var message2 = new Address
{
City = "city"
};
// Constructor should handle object being properly initialized.
// Allow custom constuctors here, do NOT report CSE001.
var message3 = new Address("city");
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:25 (15 by maintainers)
Top Results From Across the Web
Construction Proposals: Tips and Templates
Using custom brand assets, colors, and other personalized touches can win you bids even if you don't have the lowest offer. Clarify expectations....
Read more >How to do a construction proposal: examples and template
Key items to include in a construction proposal · The scope of work; · An estimate of the project cost; · The client's...
Read more >How to Write a Construction Proposal: Free Template ...
As a construction company or contractor, the first step in securing more projects is to craft a compelling construction proposal.
Read more >How to handle errors in constructors without exceptions?
I'm just going to focus on the part where he said it is sad that C++ constructors require exceptions for error handling.
Read more >Construction Proposal Software
It's quick and easy to create fully custom proposals with Buildertrend's construction proposal software. Streamline this process effectively to close more ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cezarypiatek Thank you, it works!
It looks like this one has matching constructor argument names to property names. I can make a code fix that will try to rewrite it into init block.