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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:58:52+00:00 2026-05-14T04:58:52+00:00

To give an idea of my requirement, consider these classes – class A {

  • 0

To give an idea of my requirement, consider these classes –

class A { }

class B {
    String m_sName;
    public String Name {
        get { return m_sName; }
        set { m_sName = value; }
    }

    int m_iVal;
    public int Val {
        get { return m_iVal; }
        set { m_iVal = value; }
    }

    A m_objA;
    public A AObject {
        get { return m_objA; }
        set { m_objA = value; }
    }
}

Now, I need to identify the classes of the objects passed to a function

void MyFunc(object obj) {
    Type type = obj.GetType();

    foreach (PropertyInfo pi in type.GetProperties()) {
        if (pi.PropertyType.IsClass) { //I need objects only

            if (!type.IsGenericType && type.FullName.ToLower() == "system.string") {
                object _obj = pi.GetValue(obj, null);
                //do something
            }
        }
    }
}

I don’t like this piece of code –

    if (!type.IsGenericType && type.FullName.ToLower() == "system.string") {

because then i have to filter out classes like, System.Int16, System.Int32, System.Boolean and so on.

Is there an elegant way through which I can find out if the object is of a class defined by me and not of system provided basic classes?

  • 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-14T04:58:52+00:00Added an answer on May 14, 2026 at 4:58 am

    One possible approach would be to use the Type.Assembly property and filter out anything that is not declared in one of your assemblies. The drawback of this approach is that you need to know all your assemblies at execution time, which might be hard in certain (not as common) scenarios.

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

Sidebar

Related Questions

Maybe I should first give an idea of what I want to accomplish as
To first give you an idea of what my HTML is like, I have
Can anyone give me some idea about uploading data from excel to access database
Can someone please give me an idea of how the WIRED Magazine on iPad
Does anyone know of any resources that can give me an idea of how
This is a weird one, but hopefully someone can give me an idea here.
It does not matter what programming language. Can anyone please give me an idea
Just to give you a fair idea, I am new to the web development
The idea is simple. Make a struct for Departments of a store, give it
I have a requirement to run a query against a database that will return

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.