1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using ICSharpCode.NRefactory.Ast;
7
using ICSharpCode.NRefactory.PrettyPrinter;
8
using ICSharpCode.SharpDevelop.Dom;
9
using ICSharpCode.SharpDevelop.Editor;
11
namespace ICSharpCode.FormsDesigner
13
public class VBNetDesignerGenerator : AbstractDesignerGenerator
15
protected override System.CodeDom.Compiler.CodeDomProvider CreateCodeProvider()
17
return new Microsoft.VisualBasic.VBCodeProvider();
20
protected override DomRegion GetReplaceRegion(IDocument document, IMethod method)
22
DomRegion r = method.BodyRegion;
23
return new DomRegion(r.BeginLine + 1, 1, r.EndLine, 1);
26
protected override void RemoveFieldDeclaration(IDocument document, IField field)
28
// In VB, the field region begins at the start of the declaration
29
// and ends on the first column of the line following the declaration.
30
int startOffset = document.PositionToOffset(field.Region.BeginLine, 1);
31
int endOffset = document.PositionToOffset(field.Region.EndLine, 1);
32
document.Remove(startOffset, endOffset - startOffset);
35
protected override void ReplaceFieldDeclaration(IDocument document, IField oldField, string newFieldDeclaration)
37
// In VB, the field region begins at the start of the declaration
38
// and ends on the first column of the line following the declaration.
39
int startOffset = document.PositionToOffset(oldField.Region.BeginLine, 1);
40
int endOffset = document.PositionToOffset(oldField.Region.EndLine, 1);
41
document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
44
protected override string CreateEventHandler(Type eventType, string eventMethodName, string body, string indentation)
46
string param = GenerateParams(eventType);
48
StringBuilder b = new StringBuilder();
49
b.AppendLine(indentation);
50
b.AppendLine(indentation + "Sub " + eventMethodName + "(" + param + ")");
51
if (string.IsNullOrEmpty(body)) {
52
if (ICSharpCode.FormsDesigner.Gui.OptionPanels.GeneralOptionsPanel.InsertTodoComment) {
53
body = "' TODO: Implement " + eventMethodName;
56
string singleIndent = EditorControlService.GlobalOptions.IndentationString;
57
b.AppendLine(indentation + singleIndent + body);
58
b.AppendLine(indentation + "End Sub");
62
protected string GenerateParams(Type eventType)
64
VBNetOutputVisitor v = new VBNetOutputVisitor();
65
MethodDeclaration md = ConvertEventInvokeMethodToNRefactory(this.CurrentClassPart, eventType, "name");
67
v.AppendCommaSeparatedList(md.Parameters);
72
protected override bool CompareMethodNames(string strA, string strB)
74
return String.Equals(strA, strB, StringComparison.OrdinalIgnoreCase);