protected override ContactInfo GetExportedUser(string line, IDictionary<int, PropertyInfo> mappedProperties, int fieldsCount) { try { var address = new MailAddress(line); var info = new ContactInfo { Email = address.Address }; if (!string.IsNullOrEmpty(address.DisplayName)) { if (address.DisplayName.Contains(' ')) { //Try split info.FirstName = address.DisplayName.Split(' ')[0]; info.LastName = address.DisplayName.Split(' ')[1]; } else { info.FirstName = address.DisplayName; } } return info; } catch (Exception) { //thats bad. Failed to parse an address } return base.GetExportedUser(line, mappedProperties, fieldsCount); }
protected virtual ContactInfo GetExportedUser(string line, IDictionary<int, PropertyInfo> mappedProperties, int fieldsCount) { var exportedUser = new ContactInfo(); var dataFields = GetDataFields(line); for (int j = 0; j < Math.Min(fieldsCount, dataFields.Length); j++) { var propinfo = mappedProperties[j]; if (propinfo != null) { var value = ConvertFromString(dataFields[j], propinfo.PropertyType); if (value != null) { value = Regex.Replace(value.ToString(), "(^')|(^\")|(\"$)|('$)", String.Empty); propinfo.SetValue(exportedUser, value, null); } } } try { if (string.IsNullOrEmpty(exportedUser.FirstName) && string.IsNullOrEmpty(exportedUser.LastName) && !string.IsNullOrEmpty(exportedUser.Email)) { var username = exportedUser.Email.Contains('@') ? exportedUser.Email.Substring(0, exportedUser.Email.IndexOf('@')) : exportedUser.Email; if (username.Contains('.')) { exportedUser.FirstName = username.Split('.')[0]; exportedUser.LastName = username.Split('.')[1]; } } } catch { } return exportedUser; }