I'm trying to loop my IRepository field in my class XmlSerialization with the use of Reflection. I'm not able to define a IRepository in foreach loop instead i tried with var. But i can then not call IRepository.Save, Somehow i ned to filter the generic IRepository in the foreach loop.
The type arguments for method 'Fle.SQLServer.XmlFiles.Notifier.XmlSerialization.Save(Fle.SQLServer.Core.Services.IRepository)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
I understand my problem but cant fix it.
I want to loop my IRepository fields on XmlSerialization and call save without calling each fields in the class.
using Fle.SQLServer.Core.Model;
using Fle.SQLServer.Core.Services;
namespace Fle.SQLServer.XmlFiles.Notifier
{
public class XmlSerialization : INotifier
{
private readonly IRepository<BackupDeviceLocationData> _repositoryBackupDeviceLocation;
private readonly IRepository<BackupHistoryData> _repositoryBackupHistory;
private readonly IRepository<DatabaseSizesData> _repositoryDatabaseSizes;
private readonly IRepository<DiskSystemData> _repositoryDiskSystem;
private readonly IRepository<FailedDatabaseJobsData> _repositoryFailedDatabaseJobs;
private readonly IRepository<DatabaseReplicationData> _repositoryDatabaseReplication;
private readonly IRepository<DatabaseLongRunningJobData> _repositoryDatabaseLongRunningJob;
private readonly IRepository<DatabaseSystemData> _repositoryDatabaseSystem;
private readonly IRepository<DiskBackupData> _repositoryDiskBackup;
private readonly IRepository<SqlServerAgentEventLogData> _repositorySqlServerAgentEventLog;
private readonly IRepository<SqlServerEventLogData> _repositorySqlEventLog;
private readonly IRepository<DatabaseOwnerData> _repositoryDatabaseOwner;
private readonly IRepository<RecoveryModelData> _repositoryRecoveryModel;
private readonly IRepository<BelongToSystemData> _repositoryBelongToSystem;
public XmlSerialization(IRepository<BackupDeviceLocationData> repositoryBackupDeviceLocation,
IRepository<BackupHistoryData> repositoryBackupHistory,
IRepository<DatabaseSizesData> repositoryDatabaseSizes,
IRepository<DiskSystemData> repositoryDiskSystem,
IRepository<FailedDatabaseJobsData> repositoryFailedDatabaseJobs,
IRepository<DatabaseReplicationData> repositoryDatabaseReplication,
IRepository<DatabaseLongRunningJobData> repositoryDatabaseLongRunningJob,
IRepository<DatabaseSystemData> repositoryDatabaseSystem,
IRepository<DiskBackupData> repositoryDiskBackup,
IRepository<SqlServerAgentEventLogData> repositorySqlServerAgentEventLog,
IRepository<SqlServerEventLogData> repositorySqlEventLog,
IRepository<DatabaseOwnerData> repositoryDatabaseOwner,
IRepository<RecoveryModelData> repositoryRecoveryModel,
IRepository<BelongToSystemData> repositoryBelongToSystem)
{
_repositoryBackupDeviceLocation = repositoryBackupDeviceLocation;
_repositoryBackupHistory = repositoryBackupHistory;
_repositoryDatabaseSizes = repositoryDatabaseSizes;
_repositoryDiskSystem = repositoryDiskSystem;
_repositoryFailedDatabaseJobs = repositoryFailedDatabaseJobs;
_repositoryDatabaseReplication = repositoryDatabaseReplication;
_repositoryDatabaseLongRunningJob = repositoryDatabaseLongRunningJob;
_repositoryDatabaseSystem = repositoryDatabaseSystem;
_repositoryDiskBackup = repositoryDiskBackup;
_repositorySqlServerAgentEventLog = repositorySqlServerAgentEventLog;
_repositorySqlEventLog = repositorySqlEventLog;
_repositoryDatabaseOwner = repositoryDatabaseOwner;
_repositoryRecoveryModel = repositoryRecoveryModel;
_repositoryBelongToSystem = repositoryBelongToSystem;
}
public void Notify()
{
foreach (var field in this.GetType().GetProperties())
{
field.Save();
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire