问题描述
我正在尝试将Alvaro Mendez的旧文章"RW XML文件,配置文件,INI文件或注册表"从C#转换为vb.net.我使用了一个非常好的程序"InstantVB"进行转换,但是它偶然发现了所有代码中的一项.它与转换两个事件的使用有关.一般而言,我对使用事件不是很有经验,也不知道从哪里开始尝试解决此问题.任何帮助,将不胜感激.我已经包含了原始C#中的相关代码和Converter中的VB.net代码.
任何帮助将不胜感激.
RCTaubert
有问题的C#代码如下(我在结尾处的两个罪魁祸首处用星号标记:
################################################ #############
I am trying to convert "RW XML Files, Config Files, INI files, or the Registry", an old article by Alvaro Mendez, from C# to vb.net. I use a very good program named "InstantVB" for the conversion, but it stumbled on one item out of all the code. It has to do with converting the use of two events. I am not very experienced with using events in general, and don''t know where to start in trying to fix this. Any help would be appreciated. I have included the relevant code from the original C# and the VB.net code from the Converter.
Any help would be very much appreciated.
RCTaubert
The C# code in question is as follows (I marked the two culprit lines at the end with an asterisk:
##############################################################
namespace AMS.Profile
{
/// <summary>
/// Abstract base class for all Profile classes in this namespace.
/// </summary>
/// <remarks>
/// This class contains fields and methods which are common for all the
/// derived Profile classes.
/// It fully implements most of the methods and properties of its base
/// interfaces so that
/// derived classes don't have to. </remarks>
public abstract class Profile : IProfile
{
// Fields
private string m_name;
private bool m_readOnly;
/// <summary>
/// Event used to notify that the profile is about to be changed.
/// <summary>
/// <seealso cref="Changed" />
public event ProfileChangingHandler Changing;
/// <summary>
/// Event used to notify that the profile has been changed.
/// </summary>
/// <seealso cref="Changing" />
public event ProfileChangedHandler Changed;
/// <summary>
/// Initializes a new instance of the Profile class by setting the
/// <see cref="Name" /> to <see cref="DefaultName" />. </summary>
protected Profile()
{
m_name = DefaultName;
}
/// <summary>
/// Initializes a new instance of the Profile class by setting the
/// <see cref="Name" /> to a value. </summary>
/// <param name="name">
/// The name to initialize the <see cref="Name" /> property with. </param>
protected Profile(string name)
{
m_name = name;
}
/// <summary>
/// Initializes a new instance of the Profile class based on another Profile object. </summary>
/// <param name="profile">
/// The Profile object whose properties and events are used to initialize the object being constructed. </param>
protected Profile(Profile profile)
{
m_name = profile.m_name;
m_readOnly = profile.m_readOnly;
* Changing = profile.Changing;
* Changed = profile.Changed;
}
################################################ #############
它将转换为VB.net为(再次使用星号):
################################################ #############
##############################################################
It translates to VB.net as (again I use an asterisk):
##############################################################
Namespace AMS.Profile
''' <summary>
''' Abstract base class for all Profile classes in this namespace.
''' </summary>
''' <remarks>
''' This class contains fields and methods which are common for all
''' the derived Profile classes.
''' It fully implements most of the methods and properties of its
''' base interfaces so that derived classes don't have to. </remarks>
Public MustInherit Class Profile
Implements IProfile
' Fields
Private m_name As String
Private m_readOnly As Boolean
''' <summary>
''' Event used to notify that the profile is about to be changed.
''' </summary>
''' <seealso cref="Changed" />
Public Event Changing As ProfileChangingHandler Implements IProfile.Changing
''' <summary>
''' Event used to notify that the profile has been changed.
''' </summary>
''' <seealso cref="Changing" />
Public Event Changed As ProfileChangedHandler Implements IProfile.Changed
''' <summary>
''' Initializes a new instance of the Profile class by setting the
''' <see cref="Name" /> to <see cref="DefaultName" />. </summary>
Protected Sub New()
m_name = DefaultName
End Sub
''' <summary>
''' Initializes a new instance of the Profile class by setting the
''' <see cref="Name" /> to a value. </summary>
''' <param name="name">
''' The name to initialize the <see cref="Name" /> property with. </param>
Protected Sub New(ByVal name As String)
m_name = name
End Sub
''' <summary>
''' Initializes a new instance of the Profile class based on another
''' Profile object. </summary>
''' <param name="profile">
''' The Profile object whose properties and events are used to
''' initialize the object being constructed. </param>
Protected Sub New(ByVal profile As Profile)
m_name = profile.m_name
m_readOnly = profile.m_readOnly
* AddHandler Changing, profile.Changing
* AddHandler Changed, profile.Changed
End Sub
########################################### ##################
VB.net关于这些行的投诉如下:
##############################################################
VB.net''s complaint about the lines are as follows:
'Public Event Changing(sender As Object, e As ProfileChangingArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
'Public Event Changed(sender As Object, e As ProfileChangedArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
你能告诉我在VB.net中应该如何处理吗?
谢谢.
Can you possibly tell me how this should be handled in VB.net.
Thank you.
推荐答案
这篇关于如何将事件的用法从C#转换为VB.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!