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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:27:00+00:00 2026-05-16T23:27:00+00:00

Should be easy… class Base{} class Foo:Base{} public bool Bar(Type t){ // return ???

  • 0

Should be easy…

class Base{}    
class Foo:Base{}

public bool Bar(Type t){
  // return ???
  // NB: shouldn't know anything about Foo, just Base
}

Assert.True(Bar(typeof(IEnumerable<Foo>));
Assert.False(Bar(typeof(IEnumerable<Base>));
Assert.False(Bar(typeof(string));
Assert.False(Bar(typeof(Foo));

Just to answer question why 2nd one should be false (actually – it does not matter, cause Bar argument will never be IEnumerable<Base>).

I’m trying to write FluentNhibernate auto mapping convention which maps my class enumerations to integers. I successfully did that already, but things went down when I wanted to map IEnumerable<EnumerationChild> (in my case – User.Roles).

public class EnumerationConvention:IUserTypeConvention{
    private static readonly Type OpenType=typeof(EnumerationType<>);
    public void Apply(IPropertyInstance instance){
      //this is borked atm, must implement ienumerable case
      var closedType=OpenType.MakeGenericType(instance.Property.PropertyType);
      instance.CustomType(closedType);
    }
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria){
      criteria.Expect(
        x=>typeof(Enumeration).IsAssignableFrom(x.Property.PropertyType) ||  
           typeof(IEnumerable<Enumeration>)
             .IsAssignableFrom(x.Property.PropertyType));
    }
  }
  • 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-16T23:27:01+00:00Added an answer on May 16, 2026 at 11:27 pm

    You can use Type.IsAssignableFrom(Type). However, your question isn’t really clear – you’re specifying one type, but you need two… which type is Bar meant to be checking t against?

    Note that the answer will change between .NET 3.5 and .NET 4, due to generic covariance – in .NET 3.5, for example, a List<Foo> is not assignable to IEnumerable<Base>, but in .NET 4 it is.

    EDIT: Here’s a program which prints True, True, False, False. I’m not sure why you expected the second one to be false:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    class Base{}    
    class Foo:Base{}
    
    class Test
    {
        static bool Bar(Type t)
        {
            return typeof(IEnumerable<Base>).IsAssignableFrom(t);
        }
    
        static void Main()
        {
            Console.WriteLine(Bar(typeof(IEnumerable<Foo>)));
            Console.WriteLine(Bar(typeof(IEnumerable<Base>)));
            Console.WriteLine(Bar(typeof(string)));
            Console.WriteLine(Bar(typeof(Foo)));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be easy, just curious. I know httpd is the HTTP daemon, just
It should be easy I know!!! I watched tutorial, searched for approx. 2 hours
Converting json to oher type should be easy. From the Play! documentation : var
It should be easy: <bean id=handlerMapping class=org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping> <property name=interceptors> <list> <ref bean=myInterceptor /> </list>
This one should be easy, and I think I know the right answer, but
This should be easy, but can't find anything to explain it. Say I am
This should be easy, but I'm not sure how to best go about it.
I know this should be easy to find via google, but I can't seem
I know this should be easy stuff, but for some reason the click event
I know this should be easy and I do it no probelms in mySQL

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.