c# - Converting code using generics -


i've following code uses passed object , acts on after determining type. question if convert use generics, performance advantage since i'd still have determine type of t before act upon it? save ticks on boxing/unboxing?

private void bindoptionfields(object obj, string selectedvalue, int datalanguageid)     {         string typ = obj.gettype().name;         switch(typ.tolower())          {             case "ratingscaleitem":                 setratingscale((common.ratingscaleitem)obj, datalanguageid, selectedvalue);                 break;             case "taskstatus":                 text = ((taskstatus)obj).taskname;                 optionvalue = ((taskstatus)obj).stateid.tostring();                   break;             case "planlite":                 text =  ((xyz.abc.planlite)obj).planname;                 optionvalue = ((xyz.abc.planlite)obj).id.tostring();                 break;             case "datarow":                 text =  ((datarow)obj)["textcolumn"].tostring();                 optionvalue = ((datarow)obj)["keycolumn"].tostring();                 break;             default:                 break;         }         if (optionvalue == selectedvalue)         {             selected = true;         }     } 

note: i've 3 constructors in class receive arraylist of 20 different types (similar types in arraylist particular call). loop through arraylist , call bindoptionfields() if i've write overloaded methods, i'll have overload constructors 20 cases each. can suggest less tedious solution fast well?

you're misunderstanding generics.

if convert method generic method, caller need specify generic parameter @ compile-time.
@ point, can use normal set of overloaded methods.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -