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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:01:02+00:00 2026-06-19T02:01:02+00:00

This post is based in my original post from yesterday. But I wasn’t precise

  • 0

This post is based in my original post from yesterday. But I wasn’t precise enough about my needs, so I will try again here.

Please see my current code:

public interface IPosterGenerator<T> 
{
    IQueryable<T> GetPosters();
}

public class PetPosterGenerator : IPosterGenerator<PetPoster>
{
    IQueryable<PetPoster> GetPosters()
    {
        return busLogic.GetPetPosters();
    }
}

public class FlowerPosterGenerator : IPosterGenerator<FlowerPoster>
{
    IQueryable<FlowerPoster> GetPosters()
    {
        return busLogic.GetFlowerPosters();
    }
}

public class PinBoard
{
    protected List<IPosterGenerator> PosterGenerators { get; set; }  // 1. compiler error

    public PinBoard(List<IPosterGenerator> generators)  // 2. compiler error
    {
        this.PosterGenerators = generators;
    }

    public List<BasePoster> GetPosters()
    {
        var posters = new List<BasePoster>();

        foreach (var generator in PosterGenerators)
        {
            posters.Add(generator.GetPosters());
        }

        return posters;
    }
}

My goal is to create a “PinBoard” which can return a list of posters. Each poster can be of a different type (e.g. pet poster, flower poster, etc.). Every poster has a totally different look, content and so on. But they all inherit from a BasePoster class.

All in all I am going to have about 100 different types of posters. A concrete PinBoard instance can easily contain 1000 posters and more of all different kinds of posters (in diverse order).

In order to populate the posters of a certain PinBoard, I need to feed the PinBoard with a list of certain poster generators (the amount and type of generators will change based on the context). There will be one poster generator per poster type (e.g. the PetPosterGenerator which generates a collection of pet posters).

I thought it would be nice if all my poster generators could share the same (type safe) interface. That’s why I introduced the IPosterGenerator interface.

My problem is that the code does not compile. There are two compiler errors with the same error message: Using the generic type ‘myApp.IPosterGenerator’ requires 1 type arguments

I am not surprised by the error message because I am not defining any type at these locations. It would be great if I could do something like this in the line of the first error:

protected List<IPosterGenerator<T>> PosterGenerators { get; set; }

But when I do this, the compiler can’t find type or namespace T.

Now I am kind of lost. Maybe using the generic IPosterGenerator interface is not such a good idea after all. But I am sure that at some point in my application I need to know or access the concrete poster type which a certain IPosterGenerator represents.

How would you guys approach this? Thank you very much for your support in advance.

  • 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-19T02:01:03+00:00Added an answer on June 19, 2026 at 2:01 am

    There’s no magic solution. If you want to use generics, you still need to use them. I mean that you can’t avoid them.

    In the other hand, you can take advantage of covariance in order to let the IPosterGenerator<T> T parameter accept BasePoster:

    // Check the "out" keyword in the generic parameter!
    // "out" makes the T parameter covariant.
    public interface IPosterGenerator<out T> where T : BasePoster
    {
         IQueryable<T> GetPosters();
    }
    

    Now you can do this:

    public class PinBoard
    {
        protected List<IPosterGenerator<BasePoster>> PosterGenerators { get; set; }
    
        public PinBoard(List<IPosterGenerator<BasePoster>> generators)
        {
            this.PosterGenerators = generators;
        }
    
        public List<BasePoster> GetPosters()
        {
            var posters = new List<BasePoster>();
    
            foreach (var generator in PosterGenerators)
            {
                posters.Add(generator.GetPosters());
            }
    
            return posters;
        }
    }
    

    So easy! 🙂

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

Sidebar

Related Questions

I looked at previous post based on this but they do not relate. I
I'm writing a view helper based on the ideas about partial requests from this
I've been reading this post Creating a login form in CodeIgniter based on Ion
Again, I was creating buttons dynamically based on this post and now I need
This blog post of December 2008 says that rubygems is broken on Debian-based systems.
Based on this SO post , and this example , I expect that, when
class Followup < ActiveRecord::Base belongs_to :post belongs_to :comment end This model needs to only
This post asks this question but doesn't really give an answer, so I thought
(This post is soliciting personal experiences about storing XML; please share what you know.
I posted a question about this earlier, but I have more information now and

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.