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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:07:54+00:00 2026-05-18T09:07:54+00:00

I have this delegate declaration: public delegate IEnumerable<T> SearchInputTextStrategy<T, U>(string param); Lets assume I

  • 0

I have this delegate declaration:

public delegate IEnumerable<T> SearchInputTextStrategy<T, U>(string param);

Lets assume I did create here the new SearchInputTextStrategy delegate and name it MyDelegate.

this is my method declaration:

public void BindElements<T, TDisplayProperty,TSortProperty>
(
       IEnumerable<T> dataObjects,
       Func<T, TDisplayProperty> selectorDisplayMember,
       Func<T, TSortProperty> selectorSortMember,
       string delimiter,
       // 1.) how to declare the delegate here as parameter ??
)
{
    // pass here the delegate to a private field to save it
    // 2.) how can I do that?

}

How can I do 1.) and 2.) ? 🙂

UPDATE 2:

Ok thats what I have done so far:

public class SearchProvider<T>
    {
        public delegate IEnumerable<T> SearchInputTextStrategy<T>(string param);    

        public SearchInputTextStrategy<T> SearchStrategy { get; set; }

        public T TypedValue
        {
            get
            {
                return (T)Convert.ChangeType(SearchStrategy, typeof(T));
            }
        }
    }

UserControl:

 public delegate IEnumerable<T> SearchInputTextStrategy<T>(string param);

 public void BindElements<T, TDisplayProperty,TSortProperty>
        (
            IEnumerable<T> dataObjects,
            Func<T, TDisplayProperty> selectorDisplayMember,
            Func<T, TSortProperty> selectorSortMember,
            string delimiter,
            SearchInputTextStrategy<T> searchStrategy
        )
        { 
               /// assign the searchStrategy to the SearchProvider class 
            var sp = new SearchProvider<T>();
                sp.SearchStrategy = searchStrategy  // DOES NOT WORK !!!     
        }

Please read also my comments in the Code. What I want to achieve is pass the delegate to the searchProvider to save it somewhere… The code I write here I understand up to 50 % so please bear with me Generics are new to me although I use generic List for a long time ;P

UPDATE 2:

public partial class MainWindow : Window
{
public delegate IEnumerable SearchInputTextStrategy(string param);

    private SearchInputTextStrategy<ICustomer> _strategy;

    public MainWindow()
    {
        InitializeComponent();            

        IEnumerable<ICustomer> customers = DataService.GetCustomers();                  

        _strategy = new SearchInputTextStrategy<ICustomer>(SearchCustomers);           


        ElementUserControl.BindElements(customers, c => c.FirstName, c => c.SortId, ";", _strategy);

namespace ElementTextBoxV2
{      

        public partial class MainWindow : Window
        {
            public delegate IEnumerable<ICustomer> SearchInputTextStrategy<ICustomer>(string param);

            private SearchInputTextStrategy<ICustomer> _strategy;

            public MainWindow()
            {
                InitializeComponent();            

                IEnumerable<ICustomer> customers = DataService.GetCustomers();                  

                _strategy = new SearchInputTextStrategy<ICustomer>(SearchCustomers);           


                ElementUserControl.BindElements(customers, c => c.FirstName, c => c.SortId, ";", _strategy);

                IEnumerable<ICustomer> selectedElements =  ElementUserControl.SelectedElements<ICustomer>();
            }

            // Just a Test-Methode to assure the delegate works
            public IEnumerable<ICustomer> SearchCustomers(string param)
            {
                IEnumerable<ICustomer> foundCustomers = new List<ICustomer>();
                return foundCustomers;
            }         
        }
    }

The scenario is, that the user has put the TextBoxUserControl in a MainWindow and he has to pass a delegate pointing to a searchMethod. I have implemented this with the SearchCustomers_Method. The problem is that C# can not resolve that:

    Error   1   The best overloaded method match for 'ElementTextBoxV2.ElementsView.BindElements<ElementTextBoxV2.ICustomer,string,int>(System.Collections.Generic.IEnumerable<ElementTextBoxV2.ICustomer>, System.Func<ElementTextBoxV2.ICustomer,string>, System.Func<ElementTextBoxV2.ICustomer,int>, string, ElementTextBoxV2.Provider.SearchInputTextStrategy<ElementTextBoxV2.ICustomer>)' has some invalid arguments

Error   2   Argument 5: cannot convert from 'ElementTextBoxV2.MainWindow.SearchInputTextStrategy<ElementTextBoxV2.ICustomer>' to 'ElementTextBoxV2.Provider.SearchInputTextStrategy<ElementTextBoxV2.ICustomer>'    

Do you see the problem? In any case the User must pass a delegate with the same definition the BindElements Method has!

  • 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-18T09:07:55+00:00Added an answer on May 18, 2026 at 9:07 am

    It’s odd that your SearchInputTextStrategy has two type parameters but only actually uses one… but you just need to specify the type arguments in the parameter type. For example:

    public void BindElements<T, TDisplayProperty,TSortProperty>
    (
        IEnumerable<T> dataObjects,
        Func<T, TDisplayProperty> selectorDisplayMember,
        Func<T, TSortProperty> selectorSortMember,
        string delimiter,
        SearchInputTextStrategy<T, TDisplayProperty> searchStrategy
    )
    

    I’ve only guessed at what the type arguments should be – you haven’t really said what you want the parameter to represent.

    You won’t be able to easily have a field of the right type in your class, because the class itself doesn’t know the type parameters involved. It’s possible that you should really be making your class generic, or make another class which is able to handle the delegates appropriately. Without any more information, it’s very hard to know which.

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

Sidebar

Related Questions

I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have a class with a delegate declaration as follows... Public Class MyClass Public
I have a specialized class, BusinessObjectList, with this declaration: public class BusinessObjectList<T> : List<BusinessObject>
I have this method: private delegate void watcherReader(StreamReader sr); private void watchProc(StreamReader sr) {
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need
I have this line in a javascript block in a page: res = foo('<%=
I have this setup where in my development copy I can commit changes on
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The

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.