Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helper macro to be used with StoryQ
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Module1
Sub StoryQConvert()
Dim textSelection As String
DTE.UndoContext.Open("StoryQConvert")
textSelection = DTE.ActiveDocument.Selection.Text
If (textSelection.Trim.StartsWith("""")) Then
StringToLambda()
Else
LambdaToString()
End If
DTE.UndoContext.Close()
End Sub
Sub StringToLambda()
Dim textSelection As TextSelection
Dim output As String
Dim capitalizeNext As Boolean
textSelection = DTE.ActiveDocument.Selection
capitalizeNext = True
For Each character In textSelection.Text
If (character = " " Or character = """") Then
capitalizeNext = True
Else
If capitalizeNext Then
output = output + Char.ToUpper(character)
capitalizeNext = False
Else
output = output + character
End If
End If
Next
textSelection.Text = "() => " + output + "()"
End Sub
Sub LambdaToString()
Dim textSelection As TextSelection
Dim output As String
textSelection = DTE.ActiveDocument.Selection
For Each character In textSelection.Text
If ("() =>".Contains(character)) Then
Continue For
End If
If (Char.ToUpper(character) = character) Then
output = output + " "
End If
output = output + Char.ToLower(character)
Next
textSelection.Text = """" + output.TrimStart + """"
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.