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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:08:03+00:00 2026-05-28T02:08:03+00:00

I wanted to make a dynamic method in which i pass any instance of

  • 0

I wanted to make a dynamic method in which i pass any instance of object i made, for example:

public class Employee()
{
  public string FName;
  public string SName;
  .....etc.
}

The method i want is like the following:

public void methodName(Object oObject)
{
  //lets say that i have passed object employee to it.
}

Is it possible to extract any values from the oObject, i have tried to do so but it have no attributes to do so, and when i put in the watch i can acutally see all the attribute of class employee in it.

So is there any way ?

  • 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-05-28T02:08:04+00:00Added an answer on May 28, 2026 at 2:08 am

    There are many ways.

    Update: you say you want the whole object. Casting or interfaces to expose the properties is the way foward.

    You can cast the object to the specific type:

    if (oObject is Employee)
    {
        string name = (oObject as Employee).FName;
    }
    

    You can expose an interface that defines what the method expects, then provided types implement the interface:

    public interface IFirstName
    {
        string FName { get; }
    }
    
    public void methodName(IFirstName objectWithFirstName)
    {
        string name = objectWithFirstName.FName;
    }
    

    You can use dynamic and hope for the best at runtime (.NET 4):

    public void methodName(dynamic oObject)
    {
        string name = oObject.FName;
    }
    

    And then there is reflection.

    But the better question to ask is, is this a good method? I would be a little skeptical about methods that take anything and make expectations about things… though that’s not to say it doesn’t or shouldn’t happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package de.tablayoutexample; import java.util.List; import android.os.AsyncTask; import android.util.Log; public class CallWebServiceTask extends AsyncTask<String, String,
I wanted to make a dynamic navigation bar that could identify the current page
In java, if a method NOT inherited by any subclass is called, whether dynamic
I wanted to make Map of Collections in Java, so I can make something
I wanted to make some simple file recovery software, where I want to try
I wanted to make a basic custom keypad for the iPhone , I did
I wanted to make an application that will take either the path of the
I wanted to make a function that populates a Grid in WPF with pictures.
Let's say I wanted to make a python script interface with a site like
I'm using Zend FW and wanted to make a feed reader. I did the

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.