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

  • SEARCH
  • Home
  • 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 8645561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:34:56+00:00 2026-06-12T12:34:56+00:00

I am parsing an array of values with two properties ( Key and Value

  • 0

I am parsing an array of values with two properties (Key and Value).

Based on the keyword Key certain functions are called which test the Value.

The trouble is, I am tasked with modifying the keywords for some projects for a new project. They share like 90% of the keywords but some are unique to each project and some others are common but other functions need to be called.

At the moment the code looks like:

Public Structure Options
    Public Property Key
    Public Property Value
End Structure

Public Sub CheckPresentation(OptionsList as List(of Options))
    for each Elem in Optionslist
        select case elem.key
            case 1
                if elem.Value<>"bla" then
                    logger.info("bla")
                end if
            case 2
                 ...
            case 99
                 ...
       end select
    next
End Sub

I first wanted to simply build a new class and inherit the old class. But since all of the logic is in the select cases, that would require complete rebuilding with huge code overlap. Does anybody have an idea how to build this better?

  • 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-12T12:34:58+00:00Added an answer on June 12, 2026 at 12:34 pm

    You should create a method for each of your keywords.

    e.g. for your case 1, create the following method:

    Sub LogIfNotBla(elem As Options)
        If elem.Value<>"bla" Then
            logger.info("bla")
        End If
    End Sub
    

    Do this for every keyword.

    Then, create a mapping which maps each keyword to its handler using a dictionary:

    Dim handler = new Dictionary(Of Int32, Action(Of Options)) From 
    { 
        {1,  AddressOf LogIfNotBla},
        {2,  AddressOf Foo},
        {99, AddressOf FooBar}
    }
    

    and instead of your gigantic Select Case, simply use a lookup to call the right method:

    Public Sub CheckPresentation(OptionsList as List(of Options))
        For Each elem in Optionslist
            handler(Elem.Key)(elem)
        Next
    End Sub
    

    Now you can alter the behaviour in two ways:

    Overriding:

    Mark the methods overridable and overwrite them in a subclass:

    Overrides Sub LogIfNotBla(elem As Options)
        If elem.Value<>"bla" And SomeThingElse Then
            SomeOtherLogger.info("bla")
        End If
    End Sub
    

    Reconfiguration

    Alter the handler dictionary to call other methods on specific keywords:

    handler(1) = AddressOf AnotherMethodInsteadOfLogIfNotBla
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two pages, test.php which encodes a JSON array, and test.html which I
Hey Guys I have four integer array lists which were created after parsing a
I'm having some difficulty passing values and arrays between this two functions Here's the
I'm trying to grab the value of an array that I got from parsing
I want to add an additional value into an array before passing it to
there is a xml document that i'm parsing to array.. how can i access
I need help in retrieving a JSON object and parsing the array into my
I am parsing an arbitrary length byte array that is going to be passed
I am using JSON parsing, I put data in array named JSON Array .
I have an array of strings. The array was created by parsing a long

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.