Converting ExpandoObject to a Type, What is more efficient and less time consuming, doing that client side or server side?

StackOverflow https://stackoverflow.com/questions/19351888

Question

Problem Definition:

I got an ExpandoObject that i need to convert to a Type like "Customer" Type, the problem is not achieving that, am wondering should i approach that server side or client side using javascript, i can achieve what i want both ways but which is more effective and less time consuming?

Server Side approach:

public IEnumerable<T> Convert<T>(dynamic self)
{
    List<T> model = new List<T>();
    var jsSerializer = new JavaScriptSerializer();
    foreach (var obj in self)
    {
        model.Add(jsSerializer.ConvertToType<T>(obj));
    }
    return model.AsEnumerable();
}

Client Side approach:

var model = [];
data.forEach(function (item) {
    var property = [];
    item.forEach(function (pair) {
        property[pair.Key] = pair.Value;
    });
    model.push(property);
});

Used ORM: Rob Conery's Massive

Original Response(No Conversion):

[[{ "Key": "ID", "Value": 2 }, { "Key": "customerID", "Value": 1 }, { "Key": "orderID", "Value": 1 }, { "Key": "address", "Value": "25 Ibrahim Nagy Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1381528800000)/" }, { "Key": "deliveryPersonnelID", "Value": 1 }], [{ "Key": "ID", "Value": 3 }, { "Key": "customerID", "Value": 2 }, { "Key": "orderID", "Value": 2 }, { "Key": "address", "Value": "14 Ibrahim Nagy Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1386972000000)/" }, { "Key": "deliveryPersonnelID", "Value": 2 }], [{ "Key": "ID", "Value": 4 }, { "Key": "customerID", "Value": 1 }, { "Key": "orderID", "Value": 3 }, { "Key": "address", "Value": "30 Abbas Akad Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1387922400000)/" }, { "Key": "deliveryPersonnelID", "Value": 2 }], [{ "Key": "ID", "Value": 5 }, { "Key": "customerID", "Value": 3 }, { "Key": "orderID", "Value": 4 }, { "Key": "address", "Value": "25 Hassan Maamoon Street, NasrCity, Cairo" }, { "Key": "deliveryDateTime", "Value": "/Date(1388354400000)/" }, { "Key": "deliveryPersonnelID", "Value": 3 }]]

Was it helpful?

Solution

I decided to do the conversion client side, i don't know it feels right to me, i mean let the client do some work and also it's not much of a hard work too, so why waste time server side?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top