Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8558807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:53:45+00:00 2026-06-11T15:53:45+00:00

I have some C# code to add to an existing VB.net project. The C#

  • 0

I have some C# code to add to an existing VB.net project.
The C# class is designed as a html parser

Have initally used an online converter and was able to get most of the class working, but the piece below is still not functioning. Unfortunately I lack in the knowledge to fix this.

I am posting the whole piece, but if someone can clarify the first couple of lines, I assume that would be enough.
AttributeNameValuePair is a separate class that holds the attribute.

Further down some inline functions are used, would appreciate an example of that aswell. Or would it be easier to make these as separate functions and leave only a reference inside?

Thanks beforehand for any assistance.

            private readonly Dictionary<string, Action<DocumentModel, IEnumerable<AttributeNameValuePair>>> commandsDictionary = new Dictionary<string, Action<DocumentModel, IEnumerable<AttributeNameValuePair>>>()
    {
        { "b", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Bold = true) },
        { "i", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Italic = true) },
        { "u", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.UnderlineStyle = UnderlineType.Single) },
        { "strike", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Strikethrough = true) },
        { "sub", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Subscript = true) },
        { "sup", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Superscript = true) },
        { "div", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => 
            {
              foreach(var arg in args)
              {
                  if(arg.AttributeName == "align")
                  {
                      HorizontalAlignment align;
                      switch(arg.AttributeValue)
                      {
                          case "center":
                              align = HorizontalAlignment.Center;
                              break;
                          case "right":
                              align = HorizontalAlignment.Right;
                              break;
                          case "justify":
                              align = HorizontalAlignment.Justify;
                              break;
                          default:
                              align = HorizontalAlignment.Left;
                              break;
                      }
                  }
              }
            })},
        { "br", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => doc.Sections[0].Blocks.Add(new Paragraph(doc))) },
        {  "span",  new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => {})},
        { "font", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => 
            {
                foreach(AttributeNameValuePair arg in args)
                {
                    int? size = null;
                    string fontName = null;

                    // Some dummy values.
                    if (arg.AttributeName == "size")
                        size = 10 + 3 * int.Parse(arg.AttributeValue);
                    else if (arg.AttributeName == "face")
                        fontName = arg.AttributeValue.Split(',').First();

                    var lastFormat = GetLastRun(doc).CharacterFormat;
                    if (size.HasValue)
                        lastFormat.Size = size.Value;

                    if (fontName != null)
                        lastFormat.FontName = fontName;
                }
            })},
    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:53:46+00:00Added an answer on June 11, 2026 at 3:53 pm

    Which version of vb.net is this? Lambda expressions work a bit differently in each of them. Multiline lambda is only supported in VS2010+. For VS2008 you usually end up having to turn anonymous methods into real methods and reference them via AddressOf. Automatic translation, I’ve noticed, generally seems to fail when converting anonymous/lambda type expressions from C#->VB.

    In any case, anonymous method syntax in VB is a bit clumsier and different enough, compared to C#, to be confusing. For the single line methods you would do something like this (I’m using simple types for clarity) :

    Private cmdDictionary As New Dictionary(Of String, Action(Of Integer, String))
    
    'adding items'
    cmdDictionary.Add("div", New Action(Of Integer, String) _
          (Sub(x As Integer, y As String) Console.WriteLine(y & ":" & CStr(x))))
    
    'then to access the dictionary'
    cmdDictionary.Item("div")(42, "foobar")
    

    For multiline (in vs2010) the pattern looks like:

    cmdDictionary.Add("div", New Action(Of Integer, String) _
                            (Sub(x As Integer, y As String)
                                 x = 2 * x
                                 Console.WriteLine(y & ":" & CStr(x))
                             End Sub))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem to add jQuery to some existing code, please help. We have
I have some auto-generated HTML code. When I add a float:left; on the shared
We have the following code in wizard to add existing project to a new
I have some working code with a crutch to add BOM marker to a
I have some jQuery code that runs fine until I add the jQuery UI
I'm using LLBLGen and I have some code like so: if (onlyRecentMessages) { messageBucket.PredicateExpression.Add(MessageFields.DateEffective
I have an existing StringBuilder object, the code appends some values and a delimiter
I have an existing ASP.NET website which I would like to painlessly add CMS
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some code that will change the background color of a specific label

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.