Building IEnumerable in loop

156 views Asked by At

Classes:

public class CalculateDiscountsFees
  {

    public IEnumerable<CalculateDiscountsFeesItem> Items { get; set; }
  }

public class CalculateDiscountsFeesItem
{

    public int RequestID { get; set; }


    public CalculateDiscountsFeesSale Sale { get; set; }


    public DateTime PaymentDate { get; set; }
}

public class CalculateDiscountsFeesSale
{
    public Guid UID { get; set; }

    public CalculateDiscountsFeesSaleType Type { get; set; }
}

These are the classes that are in a sdk that I need to use. I need to build CalculateDiscountsFees and then pass it back to the sdk. However I am having trouble doing this. The way I would like to do it is in a loop, create a CalculateDiscountsFeesItem and then try to add it to the to the CalculateDiscountsFees. This won't work because ienumerable doesn't have an add.

I have tried creating Extension module to create my own add but have failed to get it to work.

Here is the code that I would like to work in a ideal world. Hopefully this will give you some sort of idea of what im trying to do.

       Dim fees As New CalculateDiscountsFees
       Dim sale = New CalculateDiscountsFeesSale
       Dim feesitem = New CalculateDiscountsFeesItem
       Dim id = List.Item(0).UID
       sale.UID = id
       sale.Type = Version2.Sale.CalculateDiscountsFeesSaleType.Invoice
       feesitem.RequestID = 1
       feesitem.PaymentDate = Now()
       feesitem.Sale = sale
       fees.Items.Add( feesitem)
       Dim feeResult = CalculateDiscountsFeesSvc.Execute(companyFile, fees,     credentials)

Wondering how I can build CalculateDiscountFees. I have tried creating a list of CalculateDiscountFeesItems but am then not able to get it to CalculateDiscountFees type.

Would appreciate any suggestions. Have now spent a full working day on it with no progress.

Cheers

1

There are 1 answers

1
Karl Anderson On BEST ANSWER

Build a list of CalculateDiscountsFeesItems, then take that list and assign it to the instance of CalculateDiscountsFees's Items property, like this:

Dim fees As New CalculateDiscountsFees
Dim listOfCalculateDiscountsFeesItem As New List(Of CalculateDiscountsFeesItem)

Dim sale As New CalculateDiscountsFeesSale()
Dim id = List.Item(0).UID
sale.UID = id
sale.Type = Version2.Sale.CalculateDiscountsFeesSaleType.Invoice

Dim feesItem  As New CalculateDiscountsFeesItem()
feesitem.RequestID = 1
feesitem.PaymentDate = Now()
feesitem.Sale = sale

listOfCalculateDiscountFeesItem.Add(feesItem)

... 
Repeat above for as many fees items as you need in the list
...

Now you can take your List(Of CalculateDiscountsFeesItem) and assign it to the fees.Items property, like this:

fees.Items = listOfCalculateDiscountFeesItem.AsEnumerable()