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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:52:35+00:00 2026-06-12T11:52:35+00:00

Similar: How can I access an instance field in an abstract parent class via

  • 0

Similar: How can I access an instance field in an abstract parent class via reflection?, but only in name, no one actually uses or references reflection there.

Constraints:

  • C#
  • Must use an abstract class to inherit from
  • Must be able to pass in string as field identifier (willing to negotiate)

    public class ViewModel : BaseClass
    {
     public Car Car { get; set; }
    }
    public abstract class BaseClass
    {
     public object GetField(string field){
      //return Car if .GetField("Car") is called
     }
    }
    

    I assume this requires reflection but couldn’t quite wrap my head around it. How can access the field Car as in this example?

    • 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-12T11:52:37+00:00Added an answer on June 12, 2026 at 11:52 am

      Try this:

      [TestFixture]
      public class TravisSerialisationTest
      {
          [Test]
          public void GetPropertyValueTest()
          {
              var volvo = "Volvo";
              var viewModel = new ViewModel() { Car = volvo };
              var field = viewModel.GetField(() => viewModel.Car);
              Assert.AreEqual(volvo,field);
          }
      }
      
      public class ViewModel : BaseClass
      {
          public string Car { get; set; }
      }
      
      public abstract class BaseClass
      {
          public T GetField<T>(Expression<Func<T>> propertyExpression )
          {
              return propertyExpression.Compile().Invoke();
          }
      }
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    How can I use java reflection or similar to find project name by just
    This topic can look similar to others but I haven't found any usable answer
    How can I write a query similar to this one in LINQ to SQL
    I've a class similar to one below: namespace BLL { public partial class SomeClass
    I want to create a set of classes that are very similar and can
    BE AWARE! Creating spyware, computer viruses and similar nasties can be illegal where you
    In Java or other similar languages I can't do: a < b > c
    There is a similar question How can I assign the result of a subroutine
    How can I have a mongo query similar to the SQL ...WHERE _id >
    How can i make something similar like GMail has http://o7.no/H72gPf When application starting, gmail

    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.