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

  • Home
  • SEARCH
  • 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 4582340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:03:40+00:00 2026-05-21T21:03:40+00:00

I have something link this: public abstract class Wrapper<T, TWrapped>: where TWrapped : Wrapper<T,

  • 0

I have something link this:

public abstract class Wrapper<T, TWrapped>: where TWrapped : Wrapper<T, TWrapped>
{
   protected T baseObject;
   protected ICollection<T> baseList;
   protected ICollection<TWrapped> wrappedList;  
   public Wrapper (T base, ICollection<T> baseList, ICollection<TWrapped> wrappedList) { }
}

Then when I derive from it I need to to something like:

public class Base { }
public class Sample: Wrapper<Base, Sample> { }

Is there a way to remove the TWrapped and create a reference to the derived type? I tried using ICollection<Wrapped<T>> but then I remember that there is no covariance in ICollection.

EDIT: Clarifications, what I want with this wrapper is provide removal funcionality (and some other things) within the object (I can’t change the base object so I need a wrapper to give this funcionality and manipulate it). This abstract class will have methods like this:

void Remove()
{
   while(this.baseList.Remove(baseObject));
   this.baseList = null;
   while(this.wrappedList.Remove((TWrapped)this));
   this.wrappedList = null;
}
  • 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-21T21:03:41+00:00Added an answer on May 21, 2026 at 9:03 pm

    I end up changing the logic of how I’m going to make the lists sync and allow Items to remove themselves. I created a new class to hold a collection of the wrapped items:

    public interface IWrapper<TModel>
    {
        TModel Model { get; }
    }
    
    public class WrapperCollection<TWrapper, TModel> : ObservableCollection<TWrapper> where TWrapper : IWrapper<TModel>
    {
        protected IList<TModel> modelList;
    
        public ReadOnlyObservableCollection<TWrapper> AsReadOnly { get; private set; }
    
        protected WrapperCollection(IList<TModel> modelList)
        {
            this.modelList = modelList;
            AsReadOnly = new ReadOnlyObservableCollection<TWrapper>(this);           
        }
    
        public WrapperCollection(IList<TModel> modelList, Func<TModel, TWrapper> newWrapper)
            :this(modelList)
        {
            foreach (TModel model in modelList)
                this.Items.Add(newWrapper(model));
        }
    
        public WrapperCollection(IList<TModel> modelList, Func<TModel, WrapperCollection<TWrapper, TModel>, TWrapper> newWrapper)
            : this(modelList)
        {
            foreach (TModel model in modelList)
                this.Items.Add(newWrapper(model, this));
        }
    
        protected override void ClearItems()
        {
            modelList.Clear();
            base.ClearItems();
        }
    
        protected override void InsertItem(int index, TWrapper item)
        {
            modelList.Insert(index, item.Model);
            base.InsertItem(index, item);
        }
    
        protected override void RemoveItem(int index)
        {
            modelList.RemoveAt(index);
            base.RemoveItem(index);
        }
    
        protected override void SetItem(int index, TWrapper item)
        {
            modelList[index] = item.Model;
            base.SetItem(index, item);
        }
    }
    

    Using the sample class:

    public class wrappedInt: IWrapper<int>
    {
        private WrapperCollection<wrappedInt, int> list;
        public Model { get; private set; }
        public wrappedInt(int source, WrapperCollection<wrappedInt, int> list)
        {
            this.Model = source;
            this.list = list;
        }
        public void RemoveMe()
        {
            if (list != null)
            {
                list.Remove(this);
                list = null;
            }
        }
    }
    

    Then I can instantiate a collection with new WrapperCollection<wrappedInt, int>(listOfInts, (model, parent) => new wrappedInt(model, parent));.

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

Sidebar

Related Questions

I have something like this: <div class=content> <a href=#>A</a> </div> <div class=content> <a href=#>B</a>
I have a base class that I want to look like this: class B
When I compile something like this: public class MyClass { void myMethod(String name, String
When a user have changed something in a form, then clicks on any link
I have a link that I dynamically create which looks something like the following:
I have something like this: barProgress.BeginAnimation(RangeBase.ValueProperty, new DoubleAnimation( barProgress.Value, dNextProgressValue, new Duration(TimeSpan.FromSeconds(dDuration))); Now, how
I have something similar to the following method: public ActionResult Details(int id) { var
I have something like this: <node TEXT= txt A /> <node TEXT= txt X
So I have something like this: var xmlStatement:String = xmlObject.node[3].@thisValue; What mystery function do
My main class look like this: public class Soundboard extends Activity { SharedPreferences preferences;

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.