Принципиальный молчун
Зарегистрирован: 08 January 2005
Сообщения: 6
Примеры кода: 1
|
RE: VB.NET - > C# - перевести ! |
09 January 2005 02:29 |
|
|
|
|
Есть программа на васике, небольшая, но сложненькая, как ее перевести на шарп - не знаю, помогите, а ?
текст ниже... - создана на основе визарда для создания add-ins для VS.NET.
Public Class Connect
Implements Extensibility.IDTExtensibility2
Implements IDTCommandTarget
Dim objEventsClass As EventsClass
Dim applicationObject As EnvDTE.DTE
Dim addInInstance as EnvDTE.AddIn
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = CType(application, EnvDTE.DTE)
addInInstance = CType(addInInst, EnvDTE.AddIn)
If connectMode = Extensibility.ext_ConnectMode.ext_cm_UISetup Then
Dim objAddIn As AddIn = CType(addInInst, AddIn)
Dim CommandObj As Command
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, the Add-in or its commands may become unavailable for reasons such as:
' 1) You moved this project to a computer other than which is was originally created on.
' 2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
' 3) You add new commands or modify commands already defined.
' You will need to re-register the Add-in by building the VBAddin1Setup project,
' right-clicking the project in the Solution Explorer, and then choosing install.
' Alternatively, you could execute the ReCreateCommands.reg file the Add-in Wizard generated in
' the project directory, or run 'devenv /setup' from a command prompt.
Try
CommandObj = applicationObject.Commands.AddNamedCommand(objAddIn, "VBAddin1", "VBAddin1", "Executes the command for VBAddin1", True, 59, Nothing, 1 + 2) '1+2 == vsCommandStatusSupported+vsCommandStatusEnabled
CommandObj.AddControl(applicationObject.CommandBars.Item("Tools"))
objEventsClass = New EventsClass()
objEventsClass.DocEvents = applicationObject.Events.DocumentEvents
Catch e as System.Exception
End Try
End If
End Sub
Public Sub Exec(ByVal cmdName As String, ByVal executeOption As vsCommandExecOption, ByRef varIn As Object, ByRef varOut As Object, ByRef handled As Boolean) Implements IDTCommandTarget.Exec
handled = False
If (executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault) Then
If cmdName = "VBAddin1.Connect.VBAddin1" Then
handled = True
Exit Sub
End If
End If
End Sub
Public Sub QueryStatus(ByVal cmdName As String, ByVal neededText As vsCommandStatusTextWanted, ByRef statusOption As vsCommandStatus, ByRef commandText As Object) Implements IDTCommandTarget.QueryStatus
If neededText = EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone Then
If cmdName = "VBAddin1.Connect.VBAddin1" Then
statusOption = CType(vsCommandStatus.vsCommandStatusEnabled + vsCommandStatus.vsCommandStatusSupported, vsCommandStatus)
Else
statusOption = vsCommandStatus.vsCommandStatusUnsupported
End If
End If
End Sub
End Class
Public Module EnvironmentEvents
Public WithEvents DocEvents As EnvDTE.DocumentEvents
Public Sub DocumentEvents_DocumentSaved(ByVal doc As EnvDTE.Document) Handles DocEvents.DocumentSaved
MsgBox("Document is saved")
' Put any other code here that you want to execute when this event
' occurs.
End Sub
Public Sub DocumentEvents_DocumentOpened(ByVal doc As EnvDTE.Document) Handles DocEvents.DocumentOpened
MsgBox("Document is opened")
' Put any other code here that you want to execute when this event
' occurs.
End Sub
End Module
Public Class EventsClass
Public WithEvents DocEvents As EnvDTE.DocumentEvents
Public Sub DocumentEvents_DocumentSaved(ByVal doc As EnvDTE.Document) Handles DocEvents.DocumentSaved
MsgBox("Document is saved")
' Put any other code here that you want to execute when this event
' occurs.
End Sub
Public Sub DocumentEvents_DocumentOpened(ByVal doc As EnvDTE.Document) Handles DocEvents.DocumentOpened
MsgBox("Document is opened")
' Put any other code here that you want to execute when this event
' occurs.
End Sub
End Class
думаю что так, а вообщето загляни на http://dotnet.4all.cc/
и все это богатство пока бесплатно
public class Connect : IDTCommandTarget
{
EventsClass objEventsClass;
EnvDTE.DTE applicationObject;
EnvDTE.AddIn addInInstance;
public void OnBeginShutdown(ref System.Array custom)
{
}
public void OnAddInsUpdate(ref System.Array custom)
{
}
public void OnStartupComplete(ref System.Array custom)
{
}
public void OnDisconnection(Extensibility.ext_DisconnectMode RemoveMode, ref System.Array custom)
{
}
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
applicationObject = ((EnvDTE.DTE)(application));
addInInstance = ((EnvDTE.AddIn)(addInInst));
if (connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup) {
AddIn objAddIn = ((AddIn)(addInInst));
Command CommandObj;
try {
CommandObj = applicationObject.Commands.AddNamedCommand(objAddIn, "VBAddin1", "VBAddin1", "Executes the command for VBAddin1", true, 59, null, 1 + 2);
CommandObj.AddControl(applicationObject.CommandBars.Item("Tools"));
objEventsClass = new EventsClass();
objEventsClass.DocEvents = applicationObject.Events.DocumentEvents;
} catch (System.Exception e) {
}
}
}
public void Exec(string cmdName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if ((executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)) {
if (cmdName == "VBAddin1.Connect.VBAddin1") {
handled = true;
return;
}
}
}
public void QueryStatus(string cmdName, vsCommandStatusTextWanted neededText, ref vsCommandStatus statusOption, ref object commandText)
{
if (neededText == EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) {
if (cmdName == "VBAddin1.Connect.VBAddin1") {
statusOption = ((vsCommandStatus)(vsCommandStatus.vsCommandStatusEnabled + vsCommandStatus.vsCommandStatusSupported));
} else {
statusOption = vsCommandStatus.vsCommandStatusUnsupported;
}
}
}
}
public struct EnvironmentEvents
{
public EnvDTE.DocumentEvents DocEvents;
public void DocumentEvents_DocumentSaved(EnvDTE.Document doc)
{
MsgBox("Document is saved");
}
public void DocumentEvents_DocumentOpened(EnvDTE.Document doc)
{
MsgBox("Document is opened");
}
}
public class EventsClass
{
public EnvDTE.DocumentEvents DocEvents;
public void DocumentEvents_DocumentSaved(EnvDTE.Document doc)
{
MsgBox("Document is saved");
}
public void DocumentEvents_DocumentOpened(EnvDTE.Document doc)
{
MsgBox("Document is opened");
}
}
|
|