EventArgs を継承するクラスを DI しようとしています。このクラスを別のクラスにDIすると、「暗黙的な参照変換はありません」というエラーが表示され続けます。
以下は、VerificationStatusEventArgs クラスの宣言です。
namespace Jimbob.CsvImporter.DataVerification
{
public interface IVerificationStatusEventArgs
{
string SummaryMessage { get; set; }
bool CarriedOutToCompletion { get; set; }
List<String> ErrorLog { get; set; }
}
public class VerificationStatusEventArgs:EventArgs, IVerificationStatusEventArgs
{
public string SummaryMessage { get; set; }
public bool CarriedOutToCompletion { get; set; }
public List<String> ErrorLog { get; set; }
}
}
これを次のクラスに挿入しようとしましたが、インターフェイスを使用してイベントを宣言できません。
public interface ICsvFileVerification
{
//Error here (1)
event EventHandler<IVerificationStatusEventArgs> VerificationCompleted;
event EventHandler UpdateProgressBar;
//..
}
public class CsvFileVerification : ICsvFileVerification
{
IUserInputEntity _entity;
IEntityVerification _entityVerification;
IVerificationStatusEventArgs _dataVerificationStatus;
public CsvFileVerification(IEntityVerification entityVerification, IVerificationStatusEventArgs dataVerificationStatus)
{
_entityVerification = entityVerification;
_dataVerificationStatus = dataVerificationStatus;
}
//Error here (2)
public event EventHandler<IVerificationStatusEventArgs> VerificationCompleted;
public event EventHandler UpdateProgressBar;
public void VerifyDataManagerAsync()
{
_dataVerificationStatus.CarriedOutToCompletion = true;
_dataVerificationStatus.ErrorLog = new List<string>();
if (!_cancelToken.IsCancellationRequested)
{
try
{
_entityVerification.VerifyUserInputManager(_entity, _dataVerificationStatus.ErrorLog);
if (_dataVerificationStatus.ErrorLog.Count > 0)
{
_dataVerificationStatus.CarriedOutToCompletion = false;
_dataVerificationStatus.SummaryMessage = "Verification of user inputs failed.";
return;
}
VerifyDataTypes();
}
catch (Exception Ex)
{
//...
}
finally
{
//Call method to raise event.
OnVerificationStatusEventArgs(this, _dataVerificationStatus);
}
}
else
{
_dataVerificationStatus.SummaryMessage = "Operation was canceled before the task could be started." + Environment.NewLine;
_dataVerificationStatus.CarriedOutToCompletion = false;
OnVerificationStatusEventArgs(this, _dataVerificationStatus);
}
}
/// <summary>
/// Raises an event on the GUI thread which should be used to notify the user that the task is
/// completed and, if relevant, the exception message that was thrown.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnVerificationStatusEventArgs(object sender, IVerificationStatusEventArgs e)
{
//Error here (3)
EventHandler<IVerificationStatusEventArgs> TempHandler = VerificationCompleted;
//Avoid possible race condition.
if (TempHandler != null)
{
TempHandler(this, e);
}
}
エラー: (1)、(2) & (3):
The type 'Jimbob.CsvImporter.DataVerification.IVerificationStatusEventArgs' cannot be used as type parameter 'TEventArgs' in the generic type or method 'System.EventHandler<TEventArgs>'.
There is no implicit reference conversion from 'Jimbob.CsvImporter.DataVerification.IVerificationStatusEventArgs' to 'System.EventArgs'.
主な目的は、VerifyDataManagerAsync() をテストできるようにすることでした。これは、VerificationStatusEventArgs クラスのインスタンスだけで実際に実行できると思います。
c# チャットの誰かが、これは .net 4.0 では不可能だと示唆していましたか? これは事実ですか、それとも回避策はありますか?
ありがとう。