I have read the code of this class, and I think the Parse() and initregex() have some problem in my opinion, if the Parse() only validate the email argument, and not assign this string to it's field, it needn't to be public, and just private or protected for overriding, if the method is public, it should call initregex() first, or the regex object may not be initialized. I think the Parse should have two overloads, one is private, and assgin the argument to it's own field, the other is a static one, return a EMailAddress object and just call the private one of the new object. The oRegex is static, I think the initregex() will static better, and it's better to think of multithread too, and only have one instance for performance, the code is:
private void initregex()
{
if(oRegex == null)
{
lock(oRegex)
{
// This is double-check.
if(oRegex != null)
return;
// The originally body of initregex().
}
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think you make some valid points. Let me look further into this tonight and get back to you with any changes I intend to make in the next release. Thanks for the input!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have read the code of this class, and I think the Parse() and initregex() have some problem in my opinion, if the Parse() only validate the email argument, and not assign this string to it's field, it needn't to be public, and just private or protected for overriding, if the method is public, it should call initregex() first, or the regex object may not be initialized. I think the Parse should have two overloads, one is private, and assgin the argument to it's own field, the other is a static one, return a EMailAddress object and just call the private one of the new object. The oRegex is static, I think the initregex() will static better, and it's better to think of multithread too, and only have one instance for performance, the code is:
private void initregex()
{
if(oRegex == null)
{
lock(oRegex)
{
// This is double-check.
if(oRegex != null)
return;
// The originally body of initregex().
}
}
}
I think you make some valid points. Let me look further into this tonight and get back to you with any changes I intend to make in the next release. Thanks for the input!