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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:11:30+00:00 2026-05-12T17:11:30+00:00

I have an interface as follows: public interface ITestCase<T> where T : HtmlControl {

  • 0

I have an interface as follows:

public interface ITestCase<T> where T : HtmlControl
{
    IEnumerable<T> Execute(Manager manager);
}

HtmlControl is a base class from a 3rd party assembly.

I have two implementations of this interface.

One of them is returning null (specified by me), until I nail the logic required (not a difficult task).

The problem is, I call this 2nd implementation from my form’s codebehind:

var LoginJuniper = new Login<ArtOfTest.WebAii.Controls.HtmlControls.HtmlDiv>();
LoginProcedure.Login(textBox1.Text, new Test1());

The Login class, and all other classes, take the same type constraint argument (where T is HtmlControl, and all of them from the 3rd party API).

Also, the other issue I ran into is when I use multiple type constraints; is it possible to say T can be one of either or any multiple of these constraints? E.g. if I have:

<T> where T : HtmlControl, IElement

Can I pass in any type which may be an implementation of IElement and not HtmlControl, or vice versa? Via just the 1 interface. This would be quite useful as I wanted to pass in more types to my generic type constraint because the inteface and test cases I derive from the interface can test more than just the HtmlControls classes (can also test IElements implementations as in the 3rd party API this allows me to get screenshots and I would like to test these screenshots (get pixels, assert that the colour is correct)).

Thanks

  • 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-12T17:11:30+00:00Added an answer on May 12, 2026 at 5:11 pm

    I am unsure what exactly you want the answer to (maybe you could try summing up your actual questions).

    However in the case of using multiple constraint types, the MSDN doc says:

    By constraining the type parameter,
    you increase the number of allowable
    operations and method calls to those
    supported by the constraining type and
    all types in its inheritance
    hierarchy. Therefore, when you design
    generic classes or methods, if you
    will be performing any operation on
    the generic members beyond simple
    assignment or calling any methods not
    supported by System.Object, you will
    have to apply constraints to the type
    parameter.

    Which basically means object T must implement all the constraints you are supplying. So you cannot use the method on a type that is not derived from HtmlControl and implements IElement.

    There is a way around this, however it is not pretty, and you might aswell split things up. But you could do this:

    void Foo<T>(T arg)
    {
      if (arg is IElement)
      {
        var argAsIElement = arg as IElement;
    
        // Do something with argAsIElement
      }
      if (arg is HtmlControl)
      {
        var argAsHtmlControl = arg as HtmlControl;
    
        // Do something with argAsHtmlControl
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface declared as follows public interface ILoadObjects<T> where T : class
Let's say you have some Java code as follows: public class Base{ public void
So I have an Interface as follows public interface IMembershipProvider { bool GetUserGuidFromSSOToken(string ssoToken,
I have a interface as follows: [InheritedExport(typeof(ITransform))] public interface ITransform {...} Now, I have
I have a interface as follows: namespace Contract { [InheritedExport(typeof(ITransform))] public interface ITransform {
I have a class as follows :- interface IFilterCondition { List<Name> ApplyFilter(List<Name> namesToFilter); }
I have interface Foo public interface Foo { public void test(); } Class FooChild
I have an interface as follows: public interface ISelectEntity { List<T> GetFromDB<T, O>(O data);
I have a interface as follows public interface IX { void MethodA(); void MethodB();
If I have a client defined as follows:- public interface Client { void send(String

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.