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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:43:14+00:00 2026-06-15T07:43:14+00:00

I have a problem that I’m trying to wrap my head around. I might

  • 0

I have a problem that I’m trying to wrap my head around. I might be terribly mistaken but here is what I’m trying to do.

I have two interfaces. The second interfaces has a property that should be of a implementation of the first interface. Something like this:

public interface ITypeA{
   int Id {get;set;}
}

public interface IEntityA<T>: where T:ITypeA
{
   string Name{get;set;}
   T type{get;set;}
}

The implementations looks like this:

public class TypeA: ITypeA{
  int Id {get;set;}
}

public class EntityA: IEntityA<TypeA>{
  public string Name{get;set;}
  public TypeA type{get;set;
}

I might be doing something wrong already(?).

Now I’m implementing the repository pattern, and the interface for that looks like this:

public interface IRepo{
   IEnumerable<IEntityA<ITypeA>> GetObjects();
}

and the implementation:

public class DefaultRepo:Repo{

  //Cunstructors

   public IEnumerable<IEntitytA<ITypeA>> GetObjects(){
      var objects = SomeMethodThatReturnsTheOjects();//Get objects as EntityA[];
      return object.ToList();
   }
}

This doesn’t work.

I’ve tried to cast it as well, but getting a warning that it is a suspicious cast.

objects.Cast<IEntityA<ITypeA>[]>().ToList();

Where am I doing/thinking wrong?

Help much appriciated 🙂

EDIT:
Maybe the repository interface declaration should look like this

public interface IRepo<TEntityA> where TEntityA:IEntityA{
       IEnumerable<TEntityA> GetObjects();
    }

and the implementation:

public class DefaultRepo:Repo<EntityA>{
   ///Methods
}

Thoughts?? 🙂

  • 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-15T07:43:15+00:00Added an answer on June 15, 2026 at 7:43 am

    I’ve found a proper solution for this. I’m using json.net and I was able to solve it by doing this:

    public interface ITypeA{
       int Id {get;set;}
    }
    
    public interface ITypeB{
       int id {get;set;}
    }
    
    public class TypeA:ITypeA
       string Name{get;set;}
       int id {get;set;}
    
       [JsonConverter(typeof (ConcreteTypeConverter<TypeB>))]
       ITypeB type{get;set;}
    }
    
    public class TypeB:ITypeB
    {
       int id {get;set;}
    }
    

    And the converter looks like this:

     public class ConcreteTypeConverter<TConcrete> : JsonConverter
        {
            public override bool CanConvert(Type objectType)
            {
                //assume we can convert to anything for now
                return true;
            }
    
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                //explicitly specify the concrete type we want to create
                return serializer.Deserialize<TConcrete>(reader);
            }
    
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                //use the default serialization - it works fine
                serializer.Serialize(writer, value);
            }
        }
    

    The interfaces get cleaner and easier to read without the generics.

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

Sidebar

Related Questions

I have a problem that I cannot wrap my head around. I'm using Apache
(I have a problem that I illustrated in this question but had no correct
i have a problem that i can't solve ! (sqlite3, but i think it
this is my regex for digital dnumbers: \d+(.\d+)+(,\d+) but now i have problem that
I have the problem that my Faces ActionEvent returns a source, but the check
I have one problem that I can't explain. Here is the code in main
I have problem that im trying to get solve for like week. My goal
Have a problem that seems easy on paper but i'm having a big problem
I have a problem that I thought was easily solved, but is turning out
I have a problem that I have been trying to find a solution for

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.