Problem:
I am looking to reduce my code size because I have many very simliar
functions e.g.:
private uint GenerateAcquisitionID(AcquisitionType[] c)
{
uint max = 0;
foreach (AcquisitionType a in c)
{
uint n = Convert.ToUInt32(a.acquisitionID);
if (n max) max = n;
}
return max + 1;
}
private uint GenerateContentID(ContentType[] c)
{
uint max = 0;
foreach (ContentType a in c)
{
uint n = Convert.ToUInt32(a.contentID);
if (n max) max = n;
}
return max + 1;
}
I'm not au faix with templates, yet, is it possible to do somehting
like this with templates, or woudl this jsut make it more inefficient?
private uint GenerateID<T>(T t, string field) where T :
IEnumerable<T>
{
uint max = 0;
foreach (T a in t)
{
uint n = Convert.ToUInt32(a.field); // how to do
this?
if (n max) max = n;
}
return max + 1;
}