Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to make code more generic
Message
 
 
To
All
General information
Forum:
C#
Category:
Coding, syntax and commands
Title:
Trying to make code more generic
Miscellaneous
Thread ID:
01667539
Message ID:
01667539
Views:
54
Hi everybody,

I have the following code right now:
 JavaScriptSerializer js = new JavaScriptSerializer();
                    var itp = js.Deserialize<List<RetailItemsToPrint>>(formValues["itemsToPrint"].ToString());

                    if (itp == null)
                    {
                        labels.AlertType = "error";
                        labels.AlertMessage = Messages.noItemsToPrint;
                    }
                    else
                    {
                        // Here we may need different methods for different types of labels
                        // This currently works for retail labels only
                        RetailItemsToPrintCollection itemsToPrint = new RetailItemsToPrintCollection();
                        itemsToPrint.AddRange(itp);

                        List<ReportData> gatherData = _reportsRepository.GatherRetailLabelsData(itemsToPrint);
                        List<ReportDataSource> reportData = new List<ReportDataSource>();
                        if (gatherData != null)
                        {
                            foreach (ReportData rd in gatherData)
                            {
                                ReportDataSource rds = new ReportDataSource(rd.Name, rd.Data);
                                reportData.Add(rds);
                            }
                        }
                        labels.ReportData = reportData;
                    }
I'm trying to figure out how to change it to allow different types of labels. I added a new type RentalItemsToPrint, so when my labelType=="Rental" I need to have different type for itp, etc.

Do you know how to change this code to allow for different types?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Reply
Map
View

Click here to load this message in the networking platform