mardi 11 avril 2017

c# set entity properties from another key value entity

I have an entity which contains key and values. My key is enum. Values are string on this entity (but their data type may differ from string).

Enum example:

 public enum CallKey {
    CallDate = 1,
    CallTime = 2,
    FromPhoneNumber = 3,
    ToPhoneNumber = 4,
    Duration = 5,
    FromOperatorCode = 6,
    ToOperatorCode = 7
}

My key value entity is:

public class CallKeyValue {
    public CallKey CallKey { get; set; }
    public string Value1 { get; set; }
    public string Value2 { get; set; }
}

My example key, value data is:

CallKey |Value1     |Value2
1       |11.04.2017 |
2       |15:43      |
3       |5311234567 |
4       |5311234587 |
5       |13*min     |
6       |TR         |001
7       |TR         |002

Now, I want to create my final entity from my key value entity.

My final entity:

public class CallDetail{
    public DateTime CallDate { get; set; } //=15.04.2017 15:43
    public string FromPhoneNumber { get; set; } //=5311234567 
    public string ToPhoneNumber { get; set; } //=5311234587
    public int Duration { get; set; } //=13
    public DurationUnit DurationUnit { get; set; } //=1 (this is enum 1:min, 2:hour etc...)
    public string FromOperatorCountry { get; set; } //=TR
    public string FromOperatorId { get; set; } //=001
    public string ToOperatorCountry { get; set; } //=TR
    public string ToOperatorId { get; set; } //=002
}

Which way to set CallDetail entity? Reflection, property by property or another better way?





Aucun commentaire:

Enregistrer un commentaire