private static void PopulateCFs(Company1C company1C, int amo_acc, Company company) { foreach (var p in company1C.GetType().GetProperties()) { if (FieldLists.Companies[amo_acc].ContainsKey(p.Name) && p.GetValue(company1C) is not null) { try { if ((string)p.GetValue(company1C) == "") { continue; } } catch { } company.custom_fields_values.Add(new Custom_fields_value() { field_id = FieldLists.Companies[amo_acc][p.Name], values = new Custom_fields_value.Values[] { new Custom_fields_value.Values() { value = p.GetValue(company1C) } } }); } } }
private static void PopulateCFs(Company company, int amo_acc, Company1C company1C) { if (company.custom_fields_values is not null) { foreach (var p in company1C.GetType().GetProperties()) { if (FieldLists.Companies[amo_acc].ContainsKey(p.Name) && company.custom_fields_values.Any(x => x.field_id == FieldLists.Companies[amo_acc][p.Name])) { var value = company.custom_fields_values.First(x => x.field_id == FieldLists.Companies[amo_acc][p.Name]).values[0].value; if (p.PropertyType == typeof(Guid?) && Guid.TryParse((string)value, out Guid guidValue)) { p.SetValue(company1C, guidValue); continue; } p.SetValue(company1C, value); } } } }