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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:22:43+00:00 2026-06-15T20:22:43+00:00

I have a class that contains another poco class with simple get set properties:

  • 0

I have a class that contains another poco class with simple get set properties:

public class PersonalInformation    {
    public string FirstName { get; set; }
    public string FirstSomethingElse { get; set; }
}

I would like to find out if the current instance’s PersonalInformation.FirstName has a value. I can’t figure out how to obtain it via reflection:

foreach (PropertyInfo property in this.PersonalInformation.GetType().GetProperties())
{
    if (property.Name.Contains("First"))
    {
    if (property.GetValue(XXX, null) != null)
                            do something...

    }
}

The instance I have is “this”, which does not work, neither does this.PersonalInformation. What am I doing wrong?

Thank you for your response,

Aldo

Addendum: I’m using ASP.NET MVC3. In my razor view I can do the following very easily:

foreach (var property in Model.PersonalInformation.GetType().GetProperties()) 
{
    <div class="editor-line">
        @if (property.Name != null)
        {
        <label>@(property.Name)</label>
        @Html.Editor(property.Name)
        }
    </div>
}

there is a property.Value member that returns the current value of the field. This field comes from a poco class, as you see above. What would be the equivalent code in the code-behind?

  • 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-15T20:22:44+00:00Added an answer on June 15, 2026 at 8:22 pm

    this.PersonalInformation certainly should work. After all, that’s the target you’re talking about.

    Sample code:

    using System;
    using System.Reflection;
    
    public class PersonalInformation    {
        public string FirstName { get; set; }
        public string FirstSomethingElse { get; set; }
    }
    
    public class Foo 
    {
        public PersonalInformation PersonalInformation { get; set; }
    
        public void ShowProperties()
        {
            foreach (var property in this.PersonalInformation
                                         .GetType()
                                         .GetProperties())
            {
                var value = property.GetValue(this.PersonalInformation, null);
                Console.WriteLine("{0}: {1}", property.Name, value);
            }
        }
    }
    
    class Test
    {
        static void Main()
        {
            Foo foo = new Foo { 
                PersonalInformation = new PersonalInformation {
                    FirstName = "Fred",
                    FirstSomethingElse = "XYZ"
                }
            };
            foo.ShowProperties();
        }
    }
    

    Although if you just “want to find out if the current instance’s PersonalInformation.FirstName has a value” then I don’t see why you’re using reflection…

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

Sidebar

Related Questions

I have a simple class that contains the required properties for a request to
I have a class that contains objects of another class: public class Container {
I have a Java class that contains a list of another class. @Entity public
I have the following class called City that contains another class called Detail. public
I have a class in Qt that inherits QDockWidget. And that class contains another
I have a concrete class that contains a collection of another concrete class. I
I have a class that contains a boolean field like this one: public class
I have a class (Class B) that inherits another class (Class A) that contains
I'm developing an iOS 4 application. I have a ViewController that contains another class.
I have a problem with a simple class that contains information that I will

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.