Thursday

C# generic list copy with constructor

     
using System;
using System.Collections;
using System.Collections.Generic;
namespace Business.Web.Models {
public class DtoMapper {
// this is generic method replacing non-generic metod
// InvoiceDto_OLD provided in source below
public List<T2> Transform<T1,T2>(List<T1> i, Func<T1,T2> del)
{
List<T2> ret = new List<T2>();

foreach (T1 val in i) {
ret.Add(del(val));
}
return ret;
}

// generic method can be called as follows:
public List<InvoiceDto> InvoiceDto(List<Invoice> i) {
return Transform<Invoice,InvoiceDto> (i.ToList(),l=>new InvoiceDto(l));
}

// this is sample of old non-generic method
public List<InvoiceDto> InvoiceDto_OLD(List<Invoice> i) {
List<InvoiceDto> ret = new List<InvoiceDto>();

foreach (Invoice invoice in i) {
ret.Add(new InvoiceDto(invoice) );
}
return ret;
}
}
}

more...

No comments:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...