Hi friends,
I have model say
public class GenericPaymentMethod<T>
{
public int TenantID { get; set; }
public string Market { get; set; }
public List<T> CreditCard { get; set; }
public List<T> DebitCard { get; set; }
public List<T> BPay { get; set; }
}
public class EditPaymentMethod
{
public GenericPaymentMethod<Multicheckbox> MyProperty { get; set; }
}
public class Multicheckbox
{
public string CheckboxName { get; set; }
public bool IsChecked { get; set; }
}
I'm creating mock data as follows
public static EditPaymentMethod GetPaymentMethodDetails(int tenantID) {
dynamic obj = new EditPaymentMethod();
obj.MyProperty = new GenericPaymentMethod<Multicheckbox>();
obj.MyProperty.TenantID = 1000;
obj.MyProperty.Market = "AU";
obj.MyProperty.CreditCard = new List<Multicheckbox>(){
new Multicheckbox { CheckboxName = "Amex", IsChecked = true },
new Multicheckbox { CheckboxName = "Master Card", IsChecked = false },
new Multicheckbox { CheckboxName = "Visa", IsChecked = true }
};
obj.MyProperty.DebitCard = new List<Multicheckbox>(){
new Multicheckbox { CheckboxName = "Amex", IsChecked = false },
new Multicheckbox { CheckboxName = "Master Card", IsChecked = true },
new Multicheckbox { CheckboxName = "Visa", IsChecked = false }
};
obj.MyProperty.BPay = new List<Multicheckbox>(){
new Multicheckbox { CheckboxName = "Savings Cheque", IsChecked = true },
new Multicheckbox { CheckboxName = "Credit Card", IsChecked = false },
};
for (int i = 0; i < obj.MyProperty.BPay.Count; i++)
{
obj.BillerCodes = new List<string> { "AAA", "BBB" };
}
return obj;
}
I want to dynamically add properties to the object based on the no of item present in the BPay.
Any idea how to go about it?
Thanks in advance