Link to home
Start Free TrialLog in
Avatar of Ruffone
Ruffone

asked on

How might this method be converted to VB.Net

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

Avatar of Rose Babu
Rose Babu
Flag of India image

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

Avatar of asfahani
asfahani

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

http://converter.telerik.com/
ASKER CERTIFIED SOLUTION
Avatar of ExpertLogin_890
ExpertLogin_890
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ruffone

ASKER

Thank you