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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:36:02+00:00 2026-05-22T14:36:02+00:00

I have a class with an IList readonly property. I have created a simple

  • 0

I have a class with an IList readonly property. I have created a simple extension method, AddCSV, to add multiple items to that list. I want to create an action delegate to populate the list via the extension method. So far, I have

private Action<TListPropertyContainer, TDataValue> CreateListPropertySetter<TListPropertyContainer, TDataValue>(string listName)
{
    var list = typeof(TListPropertyContainer).GetProperty(listName);
    var method = typeof(Extensions).GetMethod("AddCSV");
    return (Action<TListPropertyContainer, TDataValue>)Delegate.CreateDelegate(typeof(Action<TListPropertyContainer, TDataValue>), list, method);
}

but obviously this isn’t working!

I am aware that there are other options. For example
a) I could inherit the list into my own customer class and add the AddCSV there
b) I could make items property read/write and set a fully populated list into my class

I’d be grateful if someone could correct me.

Many thx

Simon

  • 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-22T14:36:03+00:00Added an answer on May 22, 2026 at 2:36 pm

    There are two main problems.

    1. You are trying to invoke the method on a PropertyInfo, not a list. To get the value of the property you would need to make a call to GetValue()

    2. The call to GetMethod() doesn’t specify binding flags. I suspect it might work better with GetMethod("AddCSV", BindingFlags.Public | BindingFlags.Static).

    That being said, why are you instantiating it reflectively when you know the type and the method beforehand? It seems like you could just do:

     private Action<TListPropertyContainer, TDataValue> CreateListPropertySetter<TListPropertyContainer, TDataValue>(string listName)
     {
           var propertyInfo = typeof(TListPropertyContainer).GetProperty(listName);
           return (container,value) => {
                var list = (IList<TDataValue>)propertyInfo.GetValue(container,null);
                list.AddCSV(list);
           };
      }
    

    If I am making incorrect assumptions about the signature of the extension method or the type of property, you can still do it with Delegate.CreateDelegate(), but take the comments about the PropertyInfo and the BindingFlags into account

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

Sidebar

Related Questions

I have class method that returns a list of employees that I can iterate
I have a class with a Items property, which is an IList: class Stuff
I have a class that contains an IList<T> property called Children . Each child
I have a class CustomCollection : IList which maintains a list of CustomObject Types.
I have a class property exposing an internal IList<> through System.Collections.ObjectModel.ReadOnlyCollection<> How can I
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
I have an IList of type Breadcrumb which is just a lightweight class that
I have a class with an IList<T> property decorated with the [ImportMany(allowRecomposition = true)]
I have a simple lookup list that I will use to populate a dropdown
I have the following class: public class GraphingResults : IList<GraphingResult> { public List<GraphingResult> ToolkitResultList

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.