I am wondering what is the best way to map array values to properties in a class. Consider the following sample array describing information for an airport:
[0] "6523" string
[1] "00A" string
[2] "heliport" string
[3] "Total Rf Heliport" string
[4] "40.07080078125" string
[5] "-74.9336013793945" string
[6] "11" string
[7] "NA" string
[8] "US" string
[9] "US-PA" string
[10] "Bensalem" string
[11] "no" string
[12] "00A" string
[13] "" string
[14] "00A" string
[15] "" string
[16] "" string
[17] "" string
I have the following class:
public class Airport
{
public Airport(string[] data)
{
Action<string>[] PropertyMappings =
{
x=>this.Id=x,
x=>this.Ident=x,
x=>this.Type=x,
x=>this.Name=x,
x=>this.Latitude=x,
x=>this.Longtitude=x,
x=>this.Elevation=x,
x=>this.Continent=x,
x=>this.CountryIso=x,
x=>this.RegionIso=x,
x=>this.Municipality=x,
x=>this.ScheduledService=x,
x=>this.GPSCode=x,
x=>this.DataCode=x,
x=>this.LocalCode=x,
x=>this.HomeLink=x,
x=>this.WikipediaLink=x,
x=>this.Keywords=x
};
for(int i=0;i<data.Count();i++)
{
PropertyMappings[i](data[i]);
}
}
public string Id { get; set; }
public string Ident { get; set; }
public string Type { get; set; }
public string Name { get; set; }
public string Latitude { get; set; }
public string Longtitude { get; set; }
public string Elevation { get; set; }
public string Continent { get; set; }
public string CountryIso { get; set; }
public string RegionIso { get; set; }
public string Municipality { get; set; }
public string ScheduledService { get; set; }
public string GPSCode { get; set; }
public string DataCode { get; set; }
public string LocalCode { get; set; }
public string HomeLink { get; set; }
public string WikipediaLink { get; set; }
public string Keywords { get; set; }
}
}
And I call it like this:
Airport airport = new Airport(data);
Do you think this is a good way to do the mapping from the elements of the array to the properties of the class or is there a better way. I couldn't really find anything online. Obviously I haven't done all of the safety checks etc. This is just a small experiment.