Using C#, I need to serialize different types of objects filled with data to JSON string. I need some sort of method SerializeObject(T obj) so I can provide an object. The type of object can be different. For example, I have the following POCO-objects:
class Transfer
{
public decimal Amount { get; set; }
}
class RootTransfer
{
public int Id { get; set; }
public List<Transfer> PaymentInfo { get; set; }
}
and
class Account
{
public decimal Amount { get; set; }
}
class RootAccount
{
public int Id { get; set; }
public List<Account> Accounts { get; set; }
}
Using this SerializeObject(transfer), I want to get something like this in return:
new RootTransfer
{
PaymentInfo = new List<Transfer>
{
transfer as Transfer
}
};
Is it an abstract factory? Or repository? Please advise.
Aucun commentaire:
Enregistrer un commentaire