خرید بک لینک

Vote count: 0

I have a bunch of code doing the same thing but with just a few changes... Sounds like a great option for building a method to do the work for all of them. I need to use a class name and couldn't find anything simular enough to think I should try it - this was the closest How to use class name as parameter in C#

My classes ImportUserNotificationListModel implement interfaces with generics that have caused me a few issues in some other areas so this might be a bit harder because of that.

  public class ImportNotificationRoleListModel : IImportListBase, IImportListDatabaseCalls

and

  public class ImportUserNotificationListModel : IImportListBase, IImportListDatabaseCalls

here is the code I wish to not duplicate:

 private static bool SaveUserNotification(XDocument xdoc, int importID, SqlCoection cn, SqlTransaction tran)
    {
        try
        {

var SourceInfo = xdoc.Root.Element("UserNotifications").ToString();
            XmlSerializer serializer = new XmlSerializer(typeof(ImportUserNotificationListModel));

            using (TextReader reader = new StringReader(SourceInfo))
            {
                ImportUserNotificationListModel Listresult = (ImportUserNotificationListModel)serializer.Deserialize(reader);

                foreach (ImportUserNotificationModel lim in Listresult.ImportItems)
                {


                    Listresult.SaveImportToDatabase(lim, importID, cn, tran);
                }

                return true;

            }
        }
        catch (Exception e)
        {
            Console.Write(e.Message);
        }


        return false;
    }

Here is the copy (I have about 12 that do this)

 private static bool SaveNotificationRoles(XDocument xdoc, int importID, SqlCoection cn, SqlTransaction tran)
    {
        try
        {

            var SourceInfo = xdoc.Root.Element("NotificationRoles").ToString();
            XmlSerializer serializer = new XmlSerializer(typeof(ImportNotificationRoleListModel));

            using (TextReader reader = new StringReader(SourceInfo))
            {
                ImportNotificationRoleListModel Listresult = (ImportNotificationRoleListModel)serializer.Deserialize(reader);

                foreach (ImportNotificationRoleModel lim in Listresult.ImportItems)
                {


                    Listresult.SaveImportToDatabase(lim, importID, cn, tran);
                }

                return true;

            }
        }
        catch (Exception e)
        {
            Console.Write(e.Message);
        }


        return false;
    }
asked 27 secs ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 15 ارديبهشت 1396 ساعت: 22:10

صفحه بندی