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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:31:09+00:00 2026-05-16T14:31:09+00:00

Following a sample of my code: public abstract class<T> { public List<T> GetSomething(string q)

  • 0

Following a sample of my code:

public abstract class<T>
{
   public List<T> GetSomething(string q)
   {
      **List<T> list = new List<T>();**

      Type type = typeof(T);
      PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance);

      foreach (PropertyInfo info in props)
      {
          // at this point I need to return information from a data source query
          // and build the members (set values) according to the returning results
          // which needs to be added to a list that contains T with each property
          // within set to a value. "Some Value" should be an object instance required
          // by the Type of the PropertyInfo.

          info.SetValue(type, "Some Value", null);
          **list.Add(type);**
      }
   }

   **return list;**
}

info.SetValue(object, object, object[]) is not accessible, due to the template type, correct? My question here would be, how can I set a value on a property, contained within T?

Edit: The question confused even myself. I’ve amended the procedure above to represent my direct needs.

Thanks,
Eric

  • 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-16T14:31:09+00:00Added an answer on May 16, 2026 at 2:31 pm

    I can’t see how this makes any sense. You’re trying to set a property on an instance of T (as shown by your bindingflags,) but you are passing typeof(T) – a Type – to PropertyInfo.SetValue as the first argument. Perhaps you mean:

    public abstract class Foo<T> 
    { 
       public List<T> GetSomethingFrom(T instance) 
       { 
          Type type = typeof(T); 
          PropertyInfo[] props = type.GetProperties(BindingFlags.Public |
               BindingFlags.IgnoreCase | BindingFlags.Instance); 
    
          foreach (PropertyInfo info in props) 
          { 
              info.SetValue(instance, "Some Value", null); 
          } 
       } 
    } 
    

    In this case, we’re passing an instance of T to the GetSomethingFrom method, then passing instance to SetValue. Follow?

    -Oisin

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

Sidebar

Related Questions

Considering the following sample code: // delivery strategies public abstract class DeliveryStrategy { ...
How can I make the following code work? I don't think I quite understand
New to java... Trying to get a sample app to run. I'm including the
I'm after a definitive reference to what ASP.NET code is required to disabled browsers
I am new to Web/WCF/Services - so bear with me :) I am trying
I am trying out moq and I'm running into a problem with the following
I introduced a mapping for a business object which has (among others) a property
I'm faced with a design decision that doesn't smell to me, but gives me
I'm trying to figure out how to structure a program using Java's generics, and
I'm missing a trick here I think and can't believe I've never done this

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.