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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:52:43+00:00 2026-05-27T04:52:43+00:00

Here is the interface I need to define. I could not because generic type

  • 0

Here is the interface I need to define. I could not because generic type parameter in Parameters property does not exist. Is there a way to achieve this kind of interface definition in C#?

UPDATED
I did not want to define interface like this: ICriteria<T>.

public interface ICriteria
{
    string Text { get; set; }
    IList<IParameter<T>> Parameters { get; set; }
}

UPDATED

As more detail required why I would not want go that route. Here is more information about it.
I have Parameter interface and implementaion like this

public interface IParameter<T>
{
    string Name { get; set; }
    T Value { get; set; }
}

public class Parameter<T> : IParameter<T>
{
    public string Name { get; set; }
    public T Value { get; set; }
}

And the method consumes above implementation like this

public ICriteria BuildQuery()
    {
        ICriteria criteria = new Criteria();
        criteria.Text = "dbo.Messages";

        var chatRoom = new Parameter<int>() { Name = "ChatRoomId", Value = _chatRoomId };
        var startDate = new Parameter<DateTime>() { Name = "StartDate", Value = _startDateTime };
        var endDate = new Parameter<DateTime>() { Name = "EndDate", Value = _endDateTime };

        //I want to add all parameters to criteria instance
        criteria.Parameters.Add(chatRoom);
        criteria.Parameters.Add(startDate);
        criteria.Parameters.Add(endDate);

        return criteria;
    }

The above method creates different type of parameters and try to add them to Parameters list in ICriteria interface. Hope it make sense.

  • 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-27T04:52:44+00:00Added an answer on May 27, 2026 at 4:52 am

    As mentioned, you can’t do that. But what you could do is this:

    public interface IParameter
    {
        // Any members which don't need T
    }
    
    public interface IParameter<T> : IParameter
    {
        // Any members which do need to refer to T
    }
    
    public interface ICriteria
    {
        string Text { get; set; }
        IEnumerable<IParameter> WeakParameters { get; }
    }
    
    public interface ICriteria<T> : ICriteria
    {
        IList<IParameter<T>> StrongParameters { get; }
    }
    

    A typical implementation would make the WeakParameters call just return StrongParameters (assuming you’re using C# 4 with generic covariance). Another option would be to make the strong form hide the weak form:

    // Parameter types as before
    
    public interface ICriteria
    {
        string Text { get; set; }
        IEnumerable<IParameter> Parameters { get; }
    }
    
    public interface ICriteria<T> : ICriteria
    {
        new IList<IParameter<T>> Parameters { get; }
    }
    

    Then anything which only had a reference of compile-time type ICriteria would get the “weak” sequence, whereas anything with a reference of compile-time type ICriteria<T> would get the “strong” list.

    EDIT: This is all assuming that you want a single T for all parameters on a single ICriteria instance. If that’s not the case, then you might want:

    // Parameter types as before
    
    public interface ICriteria
    {
        string Text { get; set; }
        IList<IParameter> Parameters { get; }
    }
    

    You can add any kind of IParameter<T> to it, varying the T with each call, but when you’re reading the parameters you don’t have the information (at compile-time) about which parameter has which type (or indeed whether the parameter even implements the strongly-typed interface).

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

Sidebar

Related Questions

Basic question here. Say in my .h, I define a NSString: @interface MyGreatClass @property
I am not sure if there is any interface already exist in .Net like
I need to accept form data to a WCF-based service. Here's the interface: [OperationContract]
Here's an interface: public interface Foo<T> extends Comparable<Foo<T>> { ... } And there are
I have an interface - here's a nicely contrived version as an example: public
Currently i have some interfaces (stripped down for here): public interface IJobGroup { string
Using Fluent Interface design here if i call something like dog.Train(Running).Train(Eating).Do(Running).Do(Eating); what is the
I feel like a fool, but here goes: public interface IHasErrorController{ ErrorController ErrorController {
Here's the story. I created an interface, IVehicle . I explicitly implemented the interface
Itest is an Interface. here i mentioned like new Itest(). Then is it means

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.