0

I try describe exactly what I am looking for. I try my best to be clear.

I have 3 classes. One of them, has a list of Phones. Each item is added in order.

The second and third classes has several properties with name and index about Phones (number and type, or only number).

[DelimitedRecord("|")]
public partial class DataCSVFile
{  
    // omitted another properties
    public List<DataPhone> Phones = new List<DataPhone>();
    public class DataPhone        
    {
        public string PhoneNumber;
        public int Type;
    }
}

public partial class DataClient
{
    // omitted another properties
    public string ContPhones { get; set; } // varchar(2)
    public string Phone { get; set; } // varchar(9)
    public string TypePhone { get; set; } // varchar(1)
    public string Phone1 { get; set; } // varchar(9)
    public string TypePhone1 { get; set; } // varchar(1)
    public string Phone2 { get; set; } // varchar(9)
    public string TypePhone2 { get; set; } // varchar(1)
    public string Phone3 { get; set; } // varchar(9)
    public string TypePhone3 { get; set; } // varchar(1)
    public string Phone4 { get; set; } // varchar(9)
    public string TypePhone4 { get; set; } // varchar(1)
    public string Phone5 { get; set; } // varchar(9)
    public string TypePhone5 { get; set; } // varchar(1)
    public string Phone6 { get; set; } // varchar(9)
    public string TypePhone6 { get; set; } // varchar(1)
    public string Phone7 { get; set; } // varchar(9)
    public string TypePhone7 { get; set; } // varchar(1)
    public string Phone8 { get; set; } // varchar(9)
    public string TypePhone8 { get; set; } // varchar(1)
    public string Phone9 { get; set; } // varchar(9)
    public string TypePhone9 { get; set; } // varchar(1)

public partial class ContactCenterCalls
{
    // omitted another properties
    public string TEL1 { get; set; } // varchar(60), null
    public string TEL2 { get; set; } // varchar(60), null
    public string TEL3 { get; set; } // varchar(60), null
    public string TEL4 { get; set; } // varchar(60), null
    public string TEL5 { get; set; } // varchar(60), null
    public string TEL6 { get; set; } // varchar(60), null
    public string TEL7 { get; set; } // varchar(60), null
    public string TEL8 { get; set; } // varchar(60), null
    public string TEL9 { get; set; } // varchar(60), null
    public string TEL10 { get; set; } // varchar(60), null

Now you see how assign values to properties of 2º and 3º classes:

DataClient.ContPhones == DataCSVFile.Phones.Count

DataClient.Phone = DataCSVFile.Phones[0].PhoneNumber 
DataClient.TypePhone = DataCSVFile.Phones[0].Type
ContactCenterCalls.TEL1 = DataCSVFile.Phones[0].PhoneNumber 

DataClient.Phone1 = DataCSVFile.Phones[1].PhoneNumber 
DataClient.TypePhone1 = DataCSVFile.Phones[1].Type
ContactCenterCalls.TEL2 = DataCSVFile.Phones[1].PhoneNumber 
...
DataClient.Phone9 = DataCSVFile.Phones[9].PhoneNumber 
DataClient.TypePhone9 = DataCSVFile.Phones[9].Type
ContactCenterCalls.TEL10 = DataCSVFile.Phones[1].PhoneNumber 

The properties of 2º and 3º classes have a match: name of the field and a Index (none, 1,2,..9,10)

Any suggestions for assign values to properties programmatically ?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
  • make them arrays not "phone8" and "phone9" .. but phone[n] – BugFinder Mar 08 '18 at 10:57
  • @BugFinder I cannot modify: Reason: I use the class with Dapper, finally there are ***tables with columns*** with that name `phone8`, `phone9`, ... – Kiquenet Mar 08 '18 at 11:05
  • bleh - https://stackoverflow.com/questions/1089123/setting-a-property-by-reflection-with-a-string-value ? – BugFinder Mar 08 '18 at 11:05

0 Answers0