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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:42:43+00:00 2026-06-05T12:42:43+00:00

After almost 20 years using Visual FoxPro, I’m suffering with strong type language. :).

  • 0

After almost 20 years using Visual FoxPro, I’m suffering with strong type language. :).

I’m trying to create a generic method, using one interface, to set a DataGrid.ItemsSource property.

Here we go…

First, I have a class (POCO):

public class PersonVO
{
    public int PersonID { get; set; }
    public string Name { get; set; }
}

Then I created an interface:

public interface IBussiness
{
    List<T> GetAll<T>();
}

And then, other class that implements this interface…

public class PersonBLL : IBussiness
{
    public List<PersonVO> CreateNewList()
    {
        List<PersonVO> list = new List<PersonVO>();
        list.Add(new PersonVO() { PersonID = 1, Name = "Robert" });
        list.Add(new PersonVO() { PersonID = 2, Name = "Julie" });
        list.Add(new PersonVO() { PersonID = 3, Name = "Bernard" });
        return list;
    }

    public List<T> GetAll<T>()
    {
        return CreateNewList();
    }
}

The statement return CreateNewList() shows an error:

C#: An instance of type
‘System.Collections.Generic.List’ can
not be returned by a method of type ‘System.Collections.Generic.List’

So I changed this method to:

public List<T> GetAll<T>()
{
    return CreateNewList() as List<T>;
}

It compiles!

Now, my problem starts… I have a WPF usercontrol MyTabItemList.

My point is, I create a new WPF TabItem at runtime, and inject my BLL class (in this example PersonBLL, but in real world I have a lot of them…).

MyTabItemList myTabItem = new MyTabItemList(new PersonBLL());

MyTabItemList is something like this:

public partial class MyTabItemList : TabItem
{
    IBussiness oBLL;
    public MyTabItemList(IBussiness oBLL)
    {
        InitializeComponent();
        this.oBLL = oBLL;
        MyGrid.ItemsSource = oBLL.GetAll<object>();
    }
}

It runs ok, but doesn’t work like I would like it to.

oBLL.GetAll<object>() always returns null.

If I change <object> to <PersonBLL> (like below), it works, but in this case MyTabItemList just works with PersonBLL class:

MyGrid.ItemsSource = oBLL.GetAll<PersonBLL>();

What should I do to make it work?

  • 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-05T12:42:45+00:00Added an answer on June 5, 2026 at 12:42 pm

    Why do you want to return a generic list from a none generic component like this?

    public interface IBussiness
    {
        List<T> GetAll<T>();
    }
    

    I think your purpose is:

    public interface IBussiness<T>
    {
        List<T> GetAll();
    }
    

    and make your PersonBLL implement IBussiness<PersonVO>:

    public class PersonBLL : IBussiness<PersonVO>
    {
        public List<PersonVO> CreateNewList() { ... }
    
        public List<PersonVO> GetAll()
        {
            return CreateNewList();
        }
    }
    

    That’s one of the normal patterns.

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

Sidebar

Related Questions

After almost two years of using DVCS, it seems that one inherent flaw is
just starting with cakephp and almost with php after a few years without use
After wasting almost a day trying to achieve the following, I've decided to risk
I just finally after trying many time over the past few years, got my
I'm considering spending time learning and using LINQ to SQL but after years of
After working in Eclipse for the past 3 years and memorizing all of the
We recently started working with XML files, after many years of experience with the
I am using Visual Studio 2010, and because of the amount of debug output
After almost two days of searching and R&D finally I've derived some of the
After 15 years doing UI development, there's very little I look at and think,

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.