How might this method be converted to VB.Net

Ruffone
Ruffone used Ask the Experts™
on
I ran it through an online converter and wound up with a not so perfect convertion

    private void BuildEmail(string template, Dictionary<string, string> parameters, out string subject, out string body, out string[] attachmentFiles, out string[] linkedResourceFiles)
    {
        ArrayList pathList;

        // Get linked resources
        Regex regex = new Regex("\"cid:([^\"]+)\"", RegexOptions.Multiline | RegexOptions.IgnoreCase);
        Match match = null;

        pathList = ((match = regex.Match(template)) != null) ? new ArrayList() : null;
        while (match.Groups.Count == 2)
        {
            pathList.Add(templateFolder + match.Groups[1].Value);
            match = match.NextMatch();
        }

        linkedResourceFiles = (string[])pathList.ToArray(typeof(string));

        // Get attachments
        regex = new Regex("<!--##ATTACHMENT:([^#]+)##-->");

        pathList = ((match = regex.Match(template)) != null) ? new ArrayList() : null;
        while (match.Groups.Count == 2)
        {
            pathList.Add(templateFolder + match.Groups[1].Value);
            match = match.NextMatch();
        }

        attachmentFiles = (string[])pathList.ToArray(typeof(string));

        // Replace parameters
        template = Regex.Replace(template, "##([^#]+)##",
                                 new MatchEvaluator(delegate(Match m)
                                 {
                                     string value;
                                     if (m.Groups.Count < 2) return m.Groups[0].Value;
                                     return (parameters.TryGetValue(m.Groups[1].Value, out value)) ? value : m.Groups[0].Value;
                                 }));

        // Get body
        body = template;

        // Get subject
        regex = new Regex("<title>(.*)</title>");
        match = regex.Match(template);
        subject = match.Groups[1].Value;
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Rose BabuSenior Team Manager

Commented:
Try this

Private Sub BuildEmail(template As String, parameters As Dictionary(Of String, String), ByRef subject As String, ByRef body As String, ByRef attachmentFiles As String(), ByRef linkedResourceFiles As String())
	Dim pathList As ArrayList

	' Get linked resources
	Dim regex__1 As New Regex("""cid:([^""]+)""", RegexOptions.Multiline Or RegexOptions.IgnoreCase)
	Dim match As Match = Nothing

	pathList = If(((InlineAssignHelper(match, regex__1.Match(template))) IsNot Nothing), New ArrayList(), Nothing)
	While match.Groups.Count = 2
		pathList.Add(templateFolder + match.Groups(1).Value)
		match = match.NextMatch()
	End While

	linkedResourceFiles = DirectCast(pathList.ToArray(GetType(String)), String())

	' Get attachments
	regex__1 = New Regex("<!--##ATTACHMENT:([^#]+)##-->")

	pathList = If(((InlineAssignHelper(match, regex__1.Match(template))) IsNot Nothing), New ArrayList(), Nothing)
	While match.Groups.Count = 2
		pathList.Add(templateFolder + match.Groups(1).Value)
		match = match.NextMatch()
	End While

	attachmentFiles = DirectCast(pathList.ToArray(GetType(String)), String())

	' Replace parameters
	template = Regex.Replace(template, "##([^#]+)##", New MatchEvaluator(Function(m As Match) Do
		Dim value As String
		If m.Groups.Count < 2 Then
			Return m.Groups(0).Value
		End If
		Return If((parameters.TryGetValue(m.Groups(1).Value, value)), value, m.Groups(0).Value)
	End Function))

	' Get body
	body = template

	' Get subject
	regex__1 = New Regex("<title>(.*)</title>")
	match = regex__1.Match(template)
	subject = match.Groups(1).Value
End Sub

Open in new window

Commented:
use the following site to convert from C# to vb.net and vice versa.

http://converter.telerik.com/
Hi,

Below is the C# converted code VB.net error free


  Private Sub BuildEmail(ByVal template As String, ByVal parameters As Dictionary(Of String, String), ByRef subject As String, ByRef body As String, ByRef attachmentFiles As String(), ByRef linkedResourceFiles As String())
        Dim pathList As ArrayList

        ' Get linked resources
        Dim regex__1 As New Regex("""cid:([^""]+)""", RegexOptions.Multiline Or RegexOptions.IgnoreCase)
        Dim match As Match = Nothing

        pathList = If(((InlineAssignHelper(match, regex__1.Match(template))) IsNot Nothing), New ArrayList(), Nothing)
        While match.Groups.Count = 2
            pathList.Add(templateFolder + match.Groups(1).Value)
            match = match.NextMatch()
        End While

        linkedResourceFiles = DirectCast(pathList.ToArray(GetType(String)), String())

        ' Get attachments
        regex__1 = New Regex("<!--##ATTACHMENT:([^#]+)##-->")

        pathList = If(((InlineAssignHelper(match, regex__1.Match(template))) IsNot Nothing), New ArrayList(), Nothing)
        While match.Groups.Count = 2
            pathList.Add(templateFolder + match.Groups(1).Value)
            match = match.NextMatch()
        End While

        attachmentFiles = DirectCast(pathList.ToArray(GetType(String)), String())

        ' Replace parameters
        template = Regex.Replace(template, "##([^#]+)##", New MatchEvaluator(Function(m As Match)
                                                                                 Dim value As String
                                                                                 If m.Groups.Count < 2 Then
                                                                                     Return m.Groups(0).Value
                                                                                 End If
                                                                                 Return If((parameters.TryGetValue(m.Groups(1).Value, value)), value, m.Groups(0).Value)
                                                                             End Function))

        ' Get body
        body = template

        ' Get subject
        regex__1 = New Regex("<title>(.*)</title>")
        match = regex__1.Match(template)
        subject = match.Groups(1).Value
End Sub

Or u can try this link

http://msdn.microsoft.com/en-us/library/aa332127%28v=vs.71%29.aspx

which helps to write the regexp properly with delegate

Author

Commented:
Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial