Link to home
Start Free TrialLog in
Avatar of Big Monty
Big MontyFlag for United States of America

asked on

pass data type into function

I have the following two functions, their only difference is the type that it returns. is there any simple way to combine these two functions into a single function and pass the data type as a parameter?

        public List<CCG_OrderData> getCCG_ItemData(string url)
        {
            string jsonData = AddBracketsToJsonString(getJsonData(url));
            return JsonConvert.DeserializeObject<List<CCG_OrderData>>(jsonData);
        }

        public List<CCG_ReceivedOrders> getCCG_ItemData2(string url)
        {
            string jsonData = AddBracketsToJsonString(getJsonData(url));
            return JsonConvert.DeserializeObject<List<CCG_ReceivedOrders>>(jsonData);
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If both CCG_OrderData and CCG_ReceivedOrders had a common class they inherit from then you could use casting BUT the generic method suggested by kaufmed above is neater.

ps.  If you look closely you will see JsonConvert.DeserializeObject that you use is using the same, generic, technique.
Avatar of Big Monty

ASKER

perfect, just what I was looking for