IPAddress constructors and Parsing improvements#13
IPAddress constructors and Parsing improvements#13jsakamoto merged 11 commits intojsakamoto:masterfrom
Conversation
… to invoke proper constructor. Includes tests.
…ound range operators are accepted, but spaces within IP address digits are not allowed
|
I found adding test cases to parsing incredibly tedious, so because FWIW the only new bug I found in existing code was #14. I did find two bugs in my new parsing code (63896a3, 8e4677f) that weren't covered by original test cases, which is good reason why full coverage is important. This would be cleaner with basically any other test framework (eg, NUnit or xUnit) but I added Console logging so you can at least see which case is failing (in the test output) when running. |
|
Thank you for your suggestion.
Yes, you are right, I think too, I agree. But some constructor override versions feel like not beautiful for me.
|
Some alternative options:
I kind of thought that the array was a good balance... kept constructors and still easy to call. I still don't mind it, but I also don't mind doing the last two options I put above: subnetmask-to-bits conversion or just leaving it off entirely. |
Oops... it's my mistake. 😵
I would like to chose "Make a new constructor that takes maskbits, and a static conversion method" version. But, please keep in mind about How to resolve the conflict of constructor syntax? |
My mistake, those are same things.
There would be no conflict .. am I missing something? So desired changes:
Did I get that right? After this the following would work: var begin = IPAddress.Parse("10.0.0.2");
var end1 = IPAddress.Parse("10.0.0.29");
var range1 = new IPAddressRange(begin, end1);
var subnetMask2 = IPAddress.Parse("255.255.255.0");
var subnet2 = new IPAddressRange(begin, SubnetMaskLength(subnetMask2)); |
|
OK, I feel those constructors sets are clear, beautiful, and developer friendly 👍 Can I expect about you will resend pull request include those constructors changing? |
|
Yeah, I will update this PR with those changes. |
|
Well, I'm looking forward to your updating of this pull request. |
* Remove public IPAddressRange(IPAddress baseAddress, IPAddress subnetMask) * Change public IPAddressRange(ICollection<IPAddress> beginEnd) to public IPAddressRange(IPAddress begin, IPAddress end) * Add public static int SubnetMaskLength(IPAddress subnetMask) (and tests) * Update XML help for public IPAddressRange(IPAddress baseAddress, int maskLength) to show example use of SubnetMaskLength()
Adds new constructors so it's possible to pass in a
System.Net.IPAddressobject. If you already have instantized IPAddress objects, it's silly to have to call.ToString()and thenIPAddressRange.Parse().New constructors:
I also refactored
Parse()to call the above constructors, and then went a step further and collapsed it down into a single Regex, which is a bit more efficient and clean (related #9).