-2
同じことをやっているが、ほんの少しの変更を加えたコードがたくさんある...それらのすべての作業を行うメソッドを構築するための素晴らしいオプションのように聞こえる。これはHow to use class name as parameter in C#クラス情報を渡すC#
私のクラスには、いくつかの他の地域では私にいくつかの問題を引き起こしているジェネリック医薬品とのインタフェースを実装ImportUserNotificationListModel最も近かった - 私は、クラス名を使用する必要があると私はそれを試してみるべきだと思いするのに十分なまねたものを見つけることができませんでした このため、これは少し難しいかもしれません。ここ
public class ImportNotificationRoleListModel : IImportListBase<ImportNotificationRoleModel>, IImportListDatabaseCalls<ImportNotificationRoleModel>
と
public class ImportUserNotificationListModel : IImportListBase<ImportUserNotificationModel>, IImportListDatabaseCalls<ImportUserNotificationModel>
は私が重複しないことを望むコードである:ここでは
private static bool SaveUserNotification(XDocument xdoc, int importID, SqlConnection 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;
}
は、コピー(私は約12この操作を行うことがあります)
private static bool SaveNotificationRoles(XDocument xdoc, int importID, SqlConnection 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;
}
です