public static void Parse(Token token, ref VCard vcard) { if (string.IsNullOrWhiteSpace(token.Values[0])) { return; } var telephone = new Telephone(); var preference = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "PREF"); var type = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TYPE"); if (type.Key == null) { type = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key != "PREF"); } telephone.Preference = preference.Value.ConvertTo <int>(); telephone.Type = TelephoneTypeLookup.Parse(type.Value != "" ? type.Value : type.Key); telephone.Number = token.Values[0]; var telephones = (List <Telephone>)vcard.Telephones ?? new List <Telephone>(); telephones.Add(telephone); vcard.Telephones = telephones; }
public static void Parse(Token token, ref VCard vcard) { if (string.IsNullOrWhiteSpace(token.Values[0])) { return; } var telephone = new Telephone(); var preference = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "PREF"); //Android ASUS вместо тега TYPE пишет имя самого типа "CELL", "WORK" и т.д. var type = token.AdditionalKeyMembers.FirstOrDefault(x => x.Key == "TYPE" || x.Key == "WORK" || x.Key == "CELL" || x.Key == "HOME" || x.Key == "VOICE" || x.Key == "FAX" || x.Key == "MESSAGE" || x.Key == "PERSONAL"); //если вместо тега TYPE найдено значение типа из перечисленного списка то в качестве значения используем значение свойства KEY var typeValue = type.Key == "TYPE" ? type.Value : type.Key; telephone.Preference = preference.Value.ConvertTo <int>(); telephone.Type = TelephoneTypeLookup.Parse(typeValue); telephone.Number = token.Values[0].Replace("-", ""); var telephones = (List <Telephone>)vcard.Telephones ?? new List <Telephone>(); telephones.Add(telephone); vcard.Telephones = telephones; }