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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:39:59+00:00 2026-06-12T18:39:59+00:00

Here is my example interface: public interface IJob<T, R> where T : IStep where

  • 0

Here is my example interface:

public interface IJob<T, R>
    where T : IStep
    where R : IDelivery
{
    T Step { get; set; }
    R Delivery { get; set; }
}

Here is my example implementation

public class ImageJob<T, R> : IJob<T, R>
    where T : ImageStep
    where R : ImageDelivery
{
    public T Step { get; set; }
    public R Delivery { get; set; }
}

Both ImageStep and ImageDelivery implement their respective interfaces (IStep, IDelivery)

Now what I’m trying to do is interface all of my repository methods. Let’s take this method for example:

public void CreateJob(IJob<IStep, IDelivery> job);

So I create a new:

var job = new ImageJob<ImageStep, ImageDelivery>
{
    ...
}

And then I try to pass that into the repository method:

repository.CreateJob(job);

And I get an error saying:

Unable to cast ImageJob<ImageStep, ImageDeliver> to type IJob<IStep, Idelivery>

Can someone explain to me why this is throwing an error? Am I implementing and interfacing totally wrong?

Is there an elegant to solution to what I’m trying to do?

I want to abstract out each Job with different Step and Delivery methods, etc. Is this possible some other way? Or am I missing something entirely?

  • 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-12T18:40:00+00:00Added an answer on June 12, 2026 at 6:40 pm

    I think could use Covariance. This enables you to cast a specific Generic type to one of its Generic interfaces or base classes like:

    MyType<object> list = new MyType<MyType>;
    

    Class and interface decleration:

    public interface IMyType<out T>{...}
    public class MyType<T> : IMyType<T> {...}
    

    The “out” keyword in the Generic decleration enables the cast.

    Here is a nice page on the MSDN which may help you further

    In your case it would be (if you don’t net the setters in the interface

    public interface IJob<out T, out R>
        where T : IStep
        where R : IDelivery
    {
        T Step { get; }
        R Delivery { get; }
    }
    

    This should work with your implemented class

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

Sidebar

Related Questions

Here is the example: interface IComponentA {}; class ComponentA : IComponentA { }; interface
I have an interface - here's a nicely contrived version as an example: public
Here is an example of some code I'm working on: public interface FooMaker<T extends
Here's my current set-up: Public Interface IDatabase Function CreateParameter(name as String, dbType as <dbTypeEnumeration>)
The fictional example here. Suppose I designed a class named IODevice. This class already
I'll attempt to shorten this code example: public interface IThing { //... Stuff }
Consider the following example: interface IPropertyCollection { public MethodWrapper GetPropertySetterByName(string name); //<<-- I want
Here's an example of the architecture approach I favorited as for now: public abstract
Suppose I have interface and implementation class that implements it and I want to
Here an example http://jsfiddle.net/EhLsT/ $(window).scroll(function () { if ($(window).scrollTop() > $(#header).offset().top) { $(#floating).show(); }

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.