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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:22:43+00:00 2026-05-17T20:22:43+00:00

I have a custom control which contains a list of objects. The control is

  • 0

I have a custom control which contains a list of objects. The control is instantiated by the visual designer and then configured in code. The control is a grid which displays a list of entities.

I have an initialise method like this.

public void Initialise(ISession session, Type type, ICollection<IPersistentObject> objs)

IPersistentObject is an interface. However this doesn’t work when I want to assign a collection of something that implements IPersistentObject.

So I changed it to this.

public void Initialise<T>(ISession session, Type type, ICollection<T> objs) where T : class, IPersistentObject

But now I want to assign the objs parameter to a member variable of type ICollection<IPersistentObject> which doesn’t work.

I can’t make the class generic because it is a control which can’t have generic types AFAIK. I can’t copy the collection because the control MUST modify the passed in collection, not take a copy and modify that.

What should I do?

  • 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-17T20:22:44+00:00Added an answer on May 17, 2026 at 8:22 pm

    ICollection<T> does not support generic variance like that. As I see it, your options are:

    1. Code a wrapper around ICollection<T> that wraps a ICollection<IPersistentObject> and does the type-checking for you.
    2. Use IEnumerable<T> instead, which does support variance in the manner you describe.
    3. Use the non-generic IList, if your concrete classes implement it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to double buffer a custom control which contains buttons. I have tried
I have created a simple Asp.Net custom control which automatically combines all the correct
I'm trying to create a custom control - a button - which will have
I have a custom component which contains many promptingTextInput controls. When i click a
I have the following Problem: I create a custom control which inherits from an
I have a container of custom controls each of which have 2 controls in
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
I have a custom control that inherits from WebControl and implements IValidator, but I
I have a custom control that exposes a property. When I set it using
I have a custom control that has the following prototype. Type.registerNamespace('Demo'); Demo.CustomTextBox = function(element)

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.