-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net
Milestone
Description
Currently we have to write this code:
public static bool IsEmailAddress(this string value)
{
try
{
new System.Net.Mail.MailAddress(value);
return true;
}
catch ()
{
return false;
}
}MailAddress should have a TryParse method like Int32.TryParse.
Rationale and Usage
Throwing and catching exceptions can have a significant impact on performance. So when possible there should be a non-throwing alternative for methods that commonly fail. An example would be Int32.Parse and Int32.TryParse.
There is also an impact on debugger. If you have the IDE set to "Break on All Exceptions" in order to see where an exception is being thrown, it will also catch this even though it is not interesting.
Proposed API
class MailAddress {
public static MailAddress Parse(string address);
public static MailAddress Parse(string address, string displayName);
public static MailAddress Parse(string address, string displayName, Encoding displayNameEncoding);
public static bool TryParse(string address, out MailAddress result);
public static bool TryParse(string address, string displayName, out MailAddress result);
public static bool TryParse(string address, string displayName, Encoding displayNameEncoding, out MailAddress result);
}Details
Open Questions
nil4, satano, ddprince17, ltrzesniewski, Scott-Caldwell and 15 more
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net