0

我需要帮助将 VB.NET 接口转换为 C# 中的接口。下面的代码定义了一个事件并在一个方法中引发它。

Public Event CampaignDetailSelected(ByVal listItem As ListItem) _
Implements ICampaignMaintenanceView.CampaignDetailSelected

...

RaiseEvent CampaignDetailSelected(DirectCast(lsbCampaignDetail.SelectedItem, ListItem))

它的接口是:

Public Interface ICampaignMaintenanceView
    Event CampaignDetailSelected(listItem As ListItem)
    ...
End Interface

当我通过转换器推送上面的接口时,它会转换事件但还包含一个委托,这在 C# 中是不允许的。

谁能给我一个提示?

4

2 回答 2

1

这是我在使用 C# 与 VB.NET 时遇到的众多问题之一,尽管我很喜欢 C#,但 VB.NET 使事件变得更简单。

// Placed outside of the class
public delegate void CampaignDetailSelectedEventHandler(ListItem listItem);

// Test class to show to convert from vb.net to C# 
public class Test : ICampaignMaintenanceView
{
    public event CampaignDetailSelectedEventHandler CampaignDetailSelected; 


    protected virtual void OnCampaignDetailSelected(ListItem listItem)
    {
        if (CampaignDetailSelected != null)
        {
            CampaignDetailSelected(listItem);
        }
    }
}
于 2013-09-23T03:49:43.643 回答
0

您的 C# 委托和接口应如下所示:

public delegate void CampaignDetailSelectedEventHandler(ListItem listItem);

public interface ICampaignMaintenanceView
{
    event CampaignDetailSelectedEventHandler CampaignDetailSelected;
}
于 2013-09-23T03:52:11.113 回答