C# 转为 VB.net
小弟在将C#转为VB时,遇见如下问题,请各位路过时,指教一二,谢谢!将C#转为VB时,这段代码总是编译不成功
Public Custom Event SolicitationEvent As EventHandler
AddHandler(ByVal value As EventHandler)
_solicitationEvent += value
End AddHandler
RemoveHandler(ByVal value As EventHandler)
_solicitationEvent -= value
End RemoveHandler
End Event
错误信息:
缺少事件“SolicitationEvent”的“RaiseEvent”定义。
“Private Event _solicitationEvent(sender As Object, e As System.EventArgs)”是事件,不能直接调用。请使用“RaiseEvent”语句引发事件。
“Private Event _solicitationEvent(sender As Object, e As System.EventArgs)”是事件,不能直接调用。请使用“RaiseEvent”语句引发事件。
下面是源码
C#:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace LTP.DBUtility
{
public enum EffentNextType
{
/// <summary>
/// 对其他语句无任何影响
/// </summary>
None,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果存在则继续执行,不存在回滚事务
/// </summary>
WhenHaveContine,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
WhenNoHaveContine,
/// <summary>
/// 当前语句影响到的行数必须大于0,否则回滚事务
/// </summary>
ExcuteEffectRows,
/// <summary>
/// 引发事件-当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
SolicitationEvent
}
public class CommandInfo
{
public object ShareObject = null;
public object OriginalData = null;
event EventHandler _solicitationEvent;
public event EventHandler SolicitationEvent
{
add
{
_solicitationEvent += value;
}
remove
{
_solicitationEvent -= value;
}
}
public void OnSolicitationEvent()
{
if (_solicitationEvent != null)
{
_solicitationEvent(this,new EventArgs());
}
}
public string CommandText;
public System.[] Parameters;
public EffentNextType EffentNextType = EffentNextType.None;
public CommandInfo()
{
}
public CommandInfo(string sqlText, SqlParameter[] para)
{
= sqlText;
this.Parameters = para;
}
public CommandInfo(string sqlText, SqlParameter[] para, EffentNextType type)
{
= sqlText;
this.Parameters = para;
this.EffentNextType = type;
}
}
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Data.SqlClient
Public Class CommandInfo
Public ShareObject As Object = Nothing
Public OriginalData As Object = Nothing
Private Event _solicitationEvent As EventHandler
Public Custom Event SolicitationEvent As EventHandler
AddHandler(ByVal value As EventHandler)
_solicitationEvent += value
End AddHandler
RemoveHandler(ByVal value As EventHandler)
_solicitationEvent -= value
End RemoveHandler
End Event
Public Sub OnSolicitationEvent()
RaiseEvent _solicitationEvent(Me, New EventArgs())
End Sub
Public CommandText As String
Public Parameters As System.()
Public EffentNextType As EffentNextType = EffentNextType.None
Public Sub New()
End Sub
Public Sub New(ByVal sqlText As String, ByVal para As SqlParameter())
= sqlText
Me.Parameters = para
End Sub
Public Sub New(ByVal sqlText As String, ByVal para As SqlParameter(), ByVal type As EffentNextType)
= sqlText
Me.Parameters = para
Me.EffentNextType = type
End Sub
End Class