I have a simple extension method for filtering a LINQ IQueryable by tags. I\'m using this with LINQ to Entities with an interface of:
public interface ITaggable
You never show where this is used. I think you are already passing an IQueryable
to the method in the first place.
Proof of concept https://ideone.com/W8c66
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public interface ITaggable {}
public struct TagStruct : ITaggable {}
public class TagObject : ITaggable {}
public static IEnumerable DoSomething(IEnumerable input)
where T: ITaggable
{
foreach (var i in input) yield return i;
}
public static void Main(string[] args)
{
var structs = new [] { new TagStruct() };
var objects = new [] { new TagObject() };
Console.WriteLine(DoSomething(structs).First().GetType());
Console.WriteLine(DoSomething(objects).First().GetType());
}
}
Output
Program+TagStruct
Program+TagObject
So, it is returning the input type, not the constrained interface.
Not surprising, what would have been the result if DoSometing required two interfaces?
public static IEnumerable DoSomething(IEnumerable input)
where T: ITaggable, ISerializable
??