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 8836971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:36:48+00:00 2026-06-14T09:36:48+00:00

I wrote this method that takes in a generic parameter object. This method accepts

  • 0

I wrote this method that takes in a generic parameter object. This method accepts different parameter objects with different properties. The idea is that based on the value of the “MethodName” property, I can construct a URI base on properties of that particular parameter object

I use reflection to get the value of the property named “MethodName.” It’s not a method, just a property name.

I use the value of the MethodName property in a case statement. This seems like an inferior way to accomplish my task. Especially as the number of MethodNames grow.

Below is the source with the case statement implementation. Any help would be appreciated.


    public string ConstructBBAPIUri<T>(T parameters)
    {
        var methodName = "";
        var uri = "";
        var userId = "";
        long timeStamp = 0;
        var signature = "";
        var sessionKey = "";
        var newUserId = "";

        if (parameters != null)
        {
            methodName = parameters.GetType().GetProperty("MethodName").GetValue(parameters, null).ToString();

            switch (methodName)
            {
                case "user.login":
                    userId = parameters.GetType().GetProperty("UserId").GetValue(parameters, null).ToString();
                    timeStamp = Convert.ToInt64(parameters.GetType().GetProperty("TimeStamp").GetValue(parameters, null));
                    signature = GenerateBunchBallSignature(userId);

                    uri = "method=" + methodName + "&apiKey=" + apiKey + "&userid=" + userId + "&ts=" +
                          timeStamp + "&sig=" + signature;
                    break;

                case "user.modifyUserId":

                    //We shouldn't need the session key if user.login is being called first
                    userId = parameters.GetType().GetProperty("UserId").GetValue(parameters, null).ToString();
                    newUserId = parameters.GetType().GetProperty("NewUserId").GetValue(parameters, null).ToString();

                    uri = "method=" + methodName + "&sessionKey=" + sessionKey + "&oldUserId=" + userId +
                          "&newUserId=" + newUserId;
                    break;
            }
        }

        return uri;
    }
  • 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-14T09:36:50+00:00Added an answer on June 14, 2026 at 9:36 am

    A better design would be to delegate constructing of URI on the classes.

    1. Create an interface with method ConstructBBAPIUri();
    2. Implement the interface for new or existing classes you have code access
    3. For existing classes you don’t have access to code, inherit from those classes and implement interface. Hopefully all the properties you need for those classes are accessible, otherwise use reflection.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a method that extracts fields from an object like this: private static
I wrote a generic extension method that takes the pain out of parsing a
I write a large static method that takes a generic as a parameter argument.
How can I write a generic method that can take a Nullable object to
I wrote this method to check if a page exists or not: protected bool
I have this method (someone else wrote it!) - (CGPDFDocumentRef)getPdf { NSArray *paths =
I wrote this n-array tree class. I want to write a method to add
I want to write method which generates key for cache object. This is my
I have a method that takes a callback argument to execute asynchronously, but the
I need a method that takes a Type and returns the paths of all

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.