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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:18:46+00:00 2026-06-01T00:18:46+00:00

I have the following class definition: public interface IItem{} public class FirstObject<T, U> :

  • 0

I have the following class definition:

public interface IItem{}

public class FirstObject<T, U> : IItem
{
    private readonly Expression<Func<T, U> _field;

    public FirstObject(Expression<Func<T, U> field, U value)
    {
       _field = field;
       Value = value;
    }

    public string FieldName
    {
       get
       {
          var member = _field.Body as MemberExpression;
          if(member != null)
            return member.Member.Name;

          throw new Exception("exception message");
       }
    }

    public U FieldValue { get; private set; }
}

IList<IItem> myList = new List<IItem>();

The IItem interface its only a marker to be able to put the different types of “FirstObject” into the list.

Now I need to iterate the list and get my items back. I definitely need to know both the FieldName and the FieldValue with its specific type. For this and for some other reasons I definitely need to be able to get back the objects’ original type.

Thanks for your help.

UPDATE: I think there is some confusion about what I need to do, so I updated the code and improved on the explanation.

Thank you all for trying to help.

  • 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-01T00:18:48+00:00Added an answer on June 1, 2026 at 12:18 am

    If you want to get property ‘SomeProperty’ form all objects, that implement IItem interface, then I think you should add that property definition to IItem (It’s not just marker iterface, it states this property should exist in every object implementing it)

    public interface IItem
    {
        object SomeProperty { get; }
    }
    

    And implement it explicitly. This will not pollute iterface of your FirstObject objects.

    public class FirstObject<T, U> : IItem
    {
        public FirstObject(U value)
        {
            SomeProperty = value;
        }
    
        public U SomeProperty { get; private set; }
    
        object IItem.SomeProperty
        {
            get { return SomeProperty; }
        }
    }
    

    And now you just get that properties by casting each item to IItem interface:

    foreach (var item in myList)
    {                
       var x = item.SomeProperty; // Voila
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have the following definition: public interface MessageResponseHandler<T extends MessageBody> { public void responsed(Message<T>
I have the following abstract classes: public abstract class AbSuperClass1<K,S> { //class definition }
Let's say I have the following class definition : List<SomeClass>... public class SomeClass {
I have the following interface: public interface Iface { void Sample1(); void Sample1(bool value);
I have the following VB.NET class definition: <Serializable()> Partial Public Class Customers End Class
I have the following interface definition: public interface IResEnume<out TModel> : IEnumerable<TModel> where TModel
I have the following definitions. interface IWeapon {} class Warrior { [Inject] public IEnumerable<IWeapon>
I have the following class definition: class IRenderable { public: virtual void Render( wxBitmap
I have a following class defined @JsonTypeName(PhotoSetUpdater) public class PhotoSetUpdater { @JsonProperty(Title) private String

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.