SubSonic Forums
All Your Database Are Belong To Us

Generic function with RepositoryList

Latest post 08-19-2008 3:26 PM by yitzchok. 3 replies.
  • 08-18-2008 7:26 AM

    Generic function with RepositoryList

    I am back! meaning more silly qouestions.. Stick out tongue
    I have a simple code to populate an AutoCompleteCustomSource with data from a RepositoryList, the problem is that I want to genralize it, use the same function every time:

                // tbCompanyType = TextBox
                // companyTypeCollection = CompanyTypeCollection : RepositoryList<CompanyType,CompanyTypeCollection>
                string[] accs = new string[companyTypeCollection.Count];
                for (int i = 0; i < companyTypeCollection.Count; i++)
                {
                    accs = companyTypeCollection.Name;
                }
                tbCompanyType.AutoCompleteCustomSource.Clear();
                tbCompanyType.AutoCompleteCustomSource.AddRange(accs);

    This is the function (clearly not working):

            public void PopulateAutoComplete(RepositoryList<?, ?> repList, AutoCompleteStringCollection target)
            {
                string[] accs = new string[repList.Count];
                for (int i = 0; i < repList.Count; i++)
                {
                    accs = repList.Name;
                }
                target.Clear();
                target.AddRange(accs);
            }

  • 08-18-2008 2:20 PM In reply to

    Re: Generic function with RepositoryList

    I think what you should is create an Interface that binds them in some way so to use this service the type must implement the Interface.

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 08-19-2008 2:38 AM In reply to

    Re: Generic function with RepositoryList

    I was afraid from to get this type of answer :( was hopping there was an easy generic trick that I didn’t know about.

  • 08-19-2008 3:26 PM In reply to

    Re: Generic function with RepositoryList

    C# and VB are statically typed languages so you can't just call some property on it if it doesn't exist like you can do in dynamic languages

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

Page 1 of 1 (4 items) | RSS