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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:47:52+00:00 2026-06-15T04:47:52+00:00

I want to create a wrapper function for a generic class like so: public

  • 0

I want to create a wrapper function for a generic class like so:

public class ColumnData
{
    public static ColumnData<T> Create<T>(string name, int width, ColumnType type,
                                          Func<T, string> dataFormater)
    {
        return new ColumnData<T>(name, width, type, dataFormater);
    }
}

The Create method will be called as an argument to another function with a signature:

public void populateFromData<TDATA>(IEnumerable<TDATA> data, 
                                    params ColumnData<TDATA>[] columns)   
{
   ...
}

The intent here is to be able to do:

var myData = new List<MyDataType>();
dataListView.populateFromData(
    myData,
    ColumnData.Create("ID", 40, ColumnType.Numeric, x => x.ID.ToString());

However, Create can’t infer the correct type for itself based on the signature it’s expected to have, and thus the lambda doesn’t know itself either.

Is this a limitation of type inference, or is there a way to make this setup work?

Note: I’m willing to specify the actual data type somewhere in this function call, if necessary, but I don’t want to specify it for each .Create().

  • 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-15T04:47:54+00:00Added an answer on June 15, 2026 at 4:47 am

    As others have explained, it’s not possible with the exact syntax you want. As a workaround, you could possibly move the typing to a separate building class:

        public class ColumnDataBuilder
        {
            public static ColumnDataBuilder<T> ColumnsFor<T>(IEnumerable<T> data)
            {
                return new ColumnDataBuilder<T>(data);
            }
        }
    
        public class ColumnDataBuilder<T> : ColumnDataBuilder
        {
            public IEnumerable<T> Data { get; private set; }
    
            public ColumnDataBuilder(IEnumerable<T> data)
            {
                this.Data = data;
            }
            public ColumnData<T> Create(string name, int width, ColumnType type, Func<T, string> dataFormater)
            {
                return new ColumnData<T>(name, width, type, dataFormater);
            }
    
            public void populateFromData(params ColumnData<T>[] columns)
            {
                ///...
            }
        }
    
        public class ColumnData<T>
        {
            public ColumnData(string name, int width, ColumnType type, Func<T, string> dataFormatter)
            {
    
            }
        }
    

    Then usage might look like:

            var builder = ColumnDataBuilder.ColumnsFor(new List<MyDataType>());
            builder.populateFromData(builder.Create("ID", 40, ColumnType.Numeric, x => x.ID.ToString()));
            IEnumerable<MyDataType> data = builder.Data;
    

    Or closer to your example usage (if you want to keep populateFromData on your dataListView) in which case you can ditch the ColumnDataBuilder<T>.populateFromData method (since it seems from your comments that’s not possible to keep there):

            var myData = new List<MyDataType>();
            var builder = ColumnDataBuilder.ColumnsFor(myData);
            dataListView.populateFromData(myData, builder.Create("ID", 40, ColumnType.Numeric, x => x.ID.ToString()));
    

    Or a bit of best of both worlds:

            var builder = ColumnDataBuilder.ColumnsFor(new List<MyDataType>());
            dataListView.populateFromData(builder.Data, builder.Create("ID", 40, ColumnType.Numeric, x => x.ID.ToString()));
    

    EDIT: Considering your comments, you probably don’t want populateFromData or possibly even the IEnumerable<T> Data stored on the ColumnDataBuilder, so you might simplify to have this instead:

        public class ColumnDataBuilder<T> : ColumnDataBuilder
        {
            public ColumnData<T> Create(string name, int width, ColumnType type, Func<T, string> dataFormater)
            {
                return new ColumnData<T>(name, width, type, dataFormater);
            }
        }
    
        public class ColumnDataBuilder
        {
            public static ColumnDataBuilder<T> ColumnsFor<T>(IEnumerable<T> data)
            {
                return new ColumnDataBuilder<T>();
            }
        }
    

    With the usage from above:

            var myData = new List<MyDataType>();
            var builder = ColumnDataBuilder.ColumnsFor(myData);
            dataListView.populateFromData(myData, builder.Create("ID", 40, ColumnType.Numeric, x => x.ID.ToString()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a wrapper class so that all queries should not be
I use Emgu CV wrapper for OpenCV . I want to create function which
I want to create a class that wraps another class so that when a
I want to use boost::bind to create a boost::function inserting a new key-value pair
I want to do something like this: template<typename CType, unsigned int targetDimensions> struct GeneratePointerType
I want to create a define to parse function signature and using Boost Preprocessor
Here's what I'd like to do: I want to create a library project that
I want to be able to templatize a class on a member function without
I'm trying to create a custom hashing function for strings. I want to hash
Since PHP doesn't provide real arrays, I want to create an array class myself.

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.