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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:19:23+00:00 2026-05-28T02:19:23+00:00

i have a litte problem and i need some help :) For example i

  • 0

i have a litte problem and i need some help 🙂

For example i have a simle abstract class

public abstract class BaseDefinition
{
    public int Id { get;set; }
    public string Name { get;set; }
}

and other base class

public abstract class BaseParentClass
{
    public string Name { get;set; }
    public string Schema { get;set; }
}

and first generic abstract class

public abstrac class BaseParentClass<T> : 
    BaseParentClass where T : BaseDefinition
{
    public IList<T> Objects {get;set;}
}

and first implementations

public class ClassADefintion : BaseDefinition
{
    public bool IsChanged {get;set;}
}


public class ClassAObject : BaseParentClass<ClassADefinition>
{
     public bool OtherField {get;set;}
}

public class ClassBDefintion : BaseDefinition
{
    public bool IsBBBChanged {get;set;}
}

public class ClassBObject : BaseParentClass<ClassBDefinition>
{
     public bool OtherBBBBField {get;set;}
}

Sorry for class name, but I can’t create anything better (it’s only example)
As We see, now is all OK :).

I have some methods who returns a IEnumerable of generic implementation

IEnumerable<ClassBObject> ClassBObjectCollection;
IEnumerable<ClassAObject> ClassAObjectCollection;

Now i must create a method, who can take a generic objects in IEnumerable

public void DoWork(IEnumerable<BaseParentClass<BaseDefinition>> objects)
{
    foreach(var baseObj in objects)
    {
        foreach(var baseDef in baseObj.Objects)
        {
            // do some work
        }
    }
}

How i remember BaseObject<BaseDefinition> != ClassAObject, but compiler doesn’t put on screen any errors. I remember in .NET in generic interface We can use IN and OUT T, so i try make this

public interface IBaseParentClass<out T> where T : BaseDefinition
{
    IList<T> Objects {get;set;}
}

Yup, You can’t make a List of <out T>. Somebody have any idea for this problem ?

I can get this fields values by reflection, but i have abstract class and interface so i think is a better way.

  • 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-28T02:19:23+00:00Added an answer on May 28, 2026 at 2:19 am

    I don’t have a compiler at hand, but I think it should be possible to rewrite DoWork as such:

    public void DoWork<T>(IEnumerable<BaseObject<T>> objects) 
        where T : BaseDefinition
    {
        foreach(var baseObj in objects)
        {
            foreach(var baseDef in baseObj.Objects)
            {
                // do some work
            }
        }
    }
    

    I am not sure whether the compiler will be able to infer T for you, try it out.

    Another possibility may be that if you enumerate those objects anyway, to make Objects of Type IEnumerable(Of T).

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

Sidebar

Related Questions

I ran into a little problem and need some help: If I have an
I have a little problem. I have some text 23%, but I need some
Ok here's a little problem I would love to get some help on. I
I need a little push in the right direction. Here's my problem: I have
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,
I have a little problem, I hope U can help me;) Trouble is, that
I have a little problem where need to do a hash of a number
I'm having some problem with logic of the comparison of some periods. I have
Guys i need some help here , im getting this error here at the
I have a little DB challenge for you. Hopefully you can help. The Problem:

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.